
var scrollMinStep = 1;
var scrollMaxStep = 150;
var scrollAccelInv = 200;
var scrollDelay = 20;
var scrollActive = 0;
var scrollRound = 0;

function getScrollStep() {
	return scrollMinStep + (scrollMaxStep - scrollMinStep)*Math.log(1.0 + (scrollRound++) / scrollAccelInv );
}

function scrollLeft(divID) {
	if (scrollActive) {
		var divRef = document.getElementById(divID);
		var divWidth = parseInt(divRef.clientWidth);
		var parentWidth = parseInt(divRef.offsetParent.clientWidth);

		if (divRef.style) { divRef = divRef.style }

		scrollStep = getScrollStep();

		if (divRef.left) {
			var actLeft = parseInt(divRef.left);
			
			if (Math.abs(actLeft) < divWidth - parentWidth - 3) {
				var newLeft = actLeft - scrollStep;
				divRef.left = newLeft + "px";
		
				setTimeout( "scrollLeft('" + divID + "')", scrollDelay);	
			} else {
				scrollActive = 0;
			}
		} else {
			if (divWidth > parentWidth) {
				divRef.left = "-" + scrollStep + "px";	
		
				setTimeout( "scrollLeft('" + divID + "')", scrollDelay);	
			} else {
				scrollActive = 0;
			}
		}
	}
}

function scrollRight(divID) {
	if (scrollActive) {
		var divRef = document.getElementById(divID);
		
		if (divRef.style) { divRef = divRef.style }

		scrollStep = getScrollStep();
		
		if (divRef.left) {
			var actLeft = parseInt(divRef.left);
			
			if (actLeft < 0) {
				var newLeft = actLeft + scrollStep;
				
				if (newLeft > 0) newLeft=0;
				
				divRef.left = newLeft + "px";
				
				setTimeout( "scrollRight('" + divID + "')", scrollDelay);	
			} else {
				scrollActive = 0;
			}
		} else {
			scrollActive = 0;
		}
	}
}

function startScrollLeft(divID) {
	if (!scrollActive) {
		scrollActive = 1;
		scrollRound = 0;
		scrollLeft(divID);
	}
}

function startScrollRight(divID) {
	if (!scrollActive) {
		scrollActive = 1;
		scrollRound = 0;
		scrollRight(divID);
	}
}

function stopScroll() {
	scrollActive = 0;
	scrollStep = 1;
}

function lScrollButtonOver(buttonID, stripID) {
	var frameRef = document.getElementById(stripID);
	if (frameRef.style) frameRef = frameRef.style;

	if ( parseInt(frameRef.left) < 0) {
		var butRef = document.getElementById(buttonID);
		if (butRef.style) butRef = butRef.style;
		butRef.visibility = 'visible';
	}
}

function rScrollButtonOver(buttonID, stripID) {
	var frameRef = document.getElementById(stripID);
	var frameW = parseInt(frameRef.clientWidth);
	var parentW = parseInt(frameRef.offsetParent.clientWidth);
	
	if (frameRef.style) frameRef = frameRef.style;

	var actLeft;	
	if ( frameRef.left )
		actLeft = parseInt(frameRef.left);
	else
		actLeft = 0;

	if ( frameW + actLeft > parentW ) {
		var butRef = document.getElementById(buttonID);
		if (butRef.style) butRef = butRef.style;
		butRef.visibility = 'visible';
	}
}

function scrollButtonOut(buttonID, stripID) {
	butRef = document.getElementById(buttonID).style
	if (butRef.style) butRef = butRef.style;
	butRef.visibility = 'hidden';
	
	stopScroll();
}

