// init page
var currentLayer = 1;
var nrLayers = 4;
var blnAllowToMove = true;

jQuery(function( $ )
{	

	$.scrollTo.defaults.axis = 'xy'; 			
	$('#scroller').scrollTo( 0 );
	$.scrollTo( 0 );
	
	$.easing.easeoutqd = function (x, t, b, c, d) 
	{
		return -c *(t/=d)*(t-2) + b;
	};
	
	var scrollTime = 500;
	var moveTo = 0;
	checkArrowVisibility();
	
	// ### start: specific behaviour only for index page. scroll from left to right
	/*	$('#scroller').scrollTo('#layer2', 1, {onAfter:function()
		{
			$('#layer1-sub').show();
			$('#scroller').scrollTo('#layer1', scrollTime, {easing:'easeoutqd', onAfter:function()
			{
				$('#layer2-sub').show();
				checkArrowVisibility();
			}});
		}});*/
	// ### end
	
	// click on right arrows
	$("a.arrowClass").click(function(){
		
		if (!blnAllowToMove) return false; // dissalow movement until previous animation finished
		blnAllowToMove = false;
		
		if(this.id == 'arrowRight')
			moveTo = currentLayer + 1;
		else
			moveTo = currentLayer - 1;
		
		// safety check
		if (moveTo < 1) moveTo = 1;
		if (moveTo > nrLayers) moveTo = nrLayers;
		
		$('#scroller').scrollTo('#layer' + moveTo, scrollTime, {easing:'easeoutqd', onAfter:function()
		{
			currentLayer = moveTo; // set new pos
			checkArrowVisibility();
			blnAllowToMove = true;
		}});
		
		return false;
	});
});

function checkArrowVisibility()
{
	if (currentLayer == 1)
	{
		$('#arrowLeft').hide();
		$('#arrowRight').show();
	} 
	else if (currentLayer == nrLayers)
	{
		$('#arrowLeft').show();
		$('#arrowRight').hide();
	} 
	else 
	{
		$('#arrowLeft').show();
		$('#arrowRight').show();
	}
}
