// init page
var currentLayer = 1;
var blnAllowToMove = true;
var nrLayers = 0;
var moveTo = 0;
var scrollTime = 500;

jQuery(function( $ )
{	
	nrLayers = parseInt( $(".scroll-inner > div").size() );
	//console.log(nrLayers);
	
	$.scrollTo.defaults.axis = 'xy'; 			
	$('.scroll-container').scrollTo( 0 );
	$.scrollTo( 0 );
	
	$.easing.easeoutqd = function (x, t, b, c, d) 
	{
		return -c *(t/=d)*(t-2) + b;
	};
	
	checkArrowVisibility();
		
	// click on right arrows
	$("a.arrowClass").click(function(){
		
		
		if (!blnAllowToMove) return false; // dissalow movement until previous animation finished
		blnAllowToMove = false;
		
		if(this.id == 'arrow_right')
			moveTo = currentLayer + 1;
		else
			moveTo = currentLayer - 1;
		
		// safety check
		if (moveTo < 1) moveTo = 1;
		if (moveTo > nrLayers) moveTo = nrLayers;
			
		$('.scroll-container').scrollTo("#slide-cnt-" + moveTo, scrollTime, {easing:'easeoutqd', onAfter:function()
		{
			currentLayer = moveTo; // set new pos
			checkArrowVisibility();
			blnAllowToMove = true;
		}});
		
		return false;
	});
});

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

function go_to_slide(slide)
{
	$('.scroll-container').scrollTo('#slide-cnt-' + slide, scrollTime, {easing:'easeoutqd', onAfter:function()
	{
		currentLayer = parseInt(slide); // set new pos
		checkArrowVisibility();
		blnAllowToMove = true;
	}});
}
