/************************************************************/
/* Logical Design Javascript								*/
/* -------------------------------------------------------- */
/* logicalScroll.js v1.0.0									*/
/* Displays a scrolling div									*/
/* (c) 2009 Logical Design									*/
/* Author: Tom Thake										*/
/************************************************************/

/**
 * Vars
 */
var scrollerDiv;
var scrollerInterval;
var scrollCount;
var currentScroll = 0;
var oldScroll = 0;
var scrollDirection;

/**
 * Logical Scroll
 */
function logicalScroll( div, direction )
{
	/* Div Init */
	scrollerDiv = div;
	scrollDirection = direction;
	
	/* Count Scrolls */
	scrollCount = $( "#" + scrollerDiv + " div.scroll" ).size();
	
	/* Show First Scroll */
	showFirstScroll();
	
	/* Rotate */
	scrollerInterval = setInterval( logicalScrollRotate, 2000 );
}

/**
 * Show First Scroll
 */
function showFirstScroll()
{
	switch( scrollDirection )
	{
		case "show":
			$( "#" + scrollerDiv + " div.scroll:eq(" + currentScroll + ")" ).show();
			break;
			
		case "top":
			$( "#" + scrollerDiv + " div.scroll:eq(" + currentScroll + ")" ).css( "top", "5px" );
			break;
	}
}

/**
 * Show Scroll
 */
function showCurrentScroll()
{
	/* SCROLL!! */
	switch( scrollDirection )
	{
		case "show":
			$( "#" + scrollerDiv + " div.scroll:eq(" + currentScroll + ")" ).show();
			$( "#" + scrollerDiv + " div.scroll:eq(" + oldScroll + ")" ).hide();
			break;
			
		case "right":
			alert( "Not yet possible!!" );
			break;
			
		case "left":
			alert( "Not yet possible!!" );
			break;
			
		case "top":
			$( "#" + scrollerDiv + " div.scroll:eq(" + oldScroll + ")" ).animate( { top: -205 }, "slow", function(){
				$( this ).css( "top", "210px" );
			});
			$( "#" + scrollerDiv + " div.scroll:eq(" + currentScroll + ")" ).show().animate( { top: 5 }, "slow" );
			break;
			
		case "down":
			break;
	}
}

/**
 * Logical Scroll Rotate
 */
function logicalScrollRotate()
{
	/* Set Current Scroll */
	currentScroll = ( oldScroll + 1 ) % scrollCount;
	
	/* Show Scroll */
	showCurrentScroll();
	
	/* Set Old Scroll */
	oldScroll = currentScroll;
}
