/* Image auto scrolling script; author: Tomas Kubes 2008 */
/* Thanks to following page for handy information: http://www.developer.com/design/article.php/3681771 */

var scrollStep 			= 2; 	//setp size in pixels
var scrollDelay			= 8; 	//time-out in milliseconds
var keepScrolling 		= true;	//control variable
var timeoutCounter;				//timeout counter controller	
var scrollElementName = 'scroll_window' //element to be scrolled


function startUp()
{
	//start from the left
	document.getElementById(scrollElementName).scrollLeft = 0;
}

function scrollImageLeft ()
{
	//flip scroll direction if necessary
	if (scrollStep < 0) scrollStep =  - scrollStep;

	//stop any prvious scrolling
	clearTimeout(timeoutCounter);

	//start scrolling
	keepScrolling = true;
	doScroll();
}

function scrollImageRight ()
{
	//flip scroll direction if necessary
	if (scrollStep > 0) scrollStep =  - scrollStep;

	//stop any prvious scrolling
	clearTimeout(timeoutCounter);

	//start scrolling
	keepScrolling = true;				
	doScroll();			
}


function doScroll()
{	 			
	//check if we will not run out of bounds (both on left or right), note: step value is positive for going left and negative for going right
	if (((document.getElementById(scrollElementName).scrollLeft + scrollStep) < (document.getElementById(scrollElementName).scrollWidth - document.getElementById(scrollElementName).clientWidth)) && ((document.getElementById(scrollElementName).scrollLeft + scrollStep) >= 0))	 			
		//scroll if we still have room
		document.getElementById(scrollElementName).scrollLeft = document.getElementById(scrollElementName).scrollLeft + scrollStep;
	else 	 				
		//stop scrolling if we have reached the limits
		keepScrolling = false;
	
	//debug - print info
	//document.getElementById('scroll_stop').value = document.getElementById('scroll_window').scrollWidth+ ' ' + document.getElementById('scroll_window').scrollLeft + ' ' + document.getElementById('scroll_window').clientWidth;

	//continue scrolling slowly until user does something
	if (keepScrolling) timeoutCounter = setTimeout("doScroll()", scrollDelay);
} 

function stopScroll ()
{
	//stop any prvious scrolling
	clearTimeout(timeoutCounter);
	keepScrolling = false;								
}

function scrollImageSlower ()
{
	//change speed (remember stpe can be both negative and positive depending on direction)
	//min speed: 1 pixel
	if (Math.abs(scrollStep) >= 2) scrollStep = Math.round(scrollStep / 2);
}

function scrollImageFaster ()
{
	//change speed (remember stpe can be both negative and positive depending on direction)
	//max speed 16 pixels
	if (Math.abs(scrollStep) <= 8) scrollStep = scrollStep * 2;
}
