$(document).ready(function() 
{
	//First page button selected
	pageFlip(1, true);
});

function pageFlip (page, withoutdelay)
{
	var animationtime = 1500;
	if(withoutdelay)
		animationtime = 0;

	
	//Prevent queueueueue buildup
	if($('#pagescontainer').length==0||$('#pagescontainer').queue().length>0)
	{
		return;
	}
	
	//Set Next-button
	if($('#page-'+(page+1)).length>0)
	{
		$('#rightarrow').fadeIn(animationtime);
		$('#rightarrow').unbind('click');
		$('#rightarrow').bind('click', function()
		{
			pageFlip (page+1);
		});
	}
	else
	{
		$('#rightarrow').fadeOut(animationtime);
	}
	
	if(page>1)
	{
		$('#leftarrow').fadeIn(animationtime);
		$('#leftarrow').unbind('click');
		$('#leftarrow').bind('click', function()
		{
			pageFlip (page-1);
		});
	}
	else
	{
		$('#leftarrow').fadeOut(animationtime);
	}
	
	$('.lookbookpagelink').each(function()
	{
		if($(this).attr('id')=='lookbookpagepager-'+page)
		{
			$('.pager', this).animate
			(
				{
					color: 'black'
				}
				, animationtime
			);
			
		}
		else
		{
			$('.pager', this).animate
			(
				{
					color: '#999B9E'
				}
				, animationtime
			);
		}

	});
	$('#pagescontainer').animate
	(
		{
			left: (0-$('#page-'+page).position().left)+'px',
			top: (0-$('#page-'+page).position().top)+'px'
		}
		, animationtime
	);
}
