var nbcbp=4;
var nbpage=0;
var currpage=0;
$(document).ready(function()
{
	$('li').hover(
		function(){ $(this).addClass('sfhover');},
		function(){ $(this).removeClass('sfhover');}
	);
	
	$('.choco .item a').click(function()
	{
		id=$(this).attr('href');
		$(".mask_desc").stop().scrollTo($(id),800,{axis:"x"});
		return false;
	});
	
	
	nbpage=Math.ceil($(".mask_choco .item").length/nbcbp);
	currpage=0;
	checkArrow();
	$('.suiv').click(function()
	{
		currpage++;
		if(currpage>nbpage-1)
			currpage=nbpage-1;
		gotoPage();
		return false;
	});
	
	$('.prec').click(function()
	{
		currpage--;
		if(currpage<0)
			currpage=0;
		gotoPage();
		return false;
	});
	$('.layer, .pub').click(function()
	{
		$('.layer,.pub').fadeOut('fast');
	});

});

$(window).scroll(function() {
    $('.layer').css('top', $(this).scrollTop() + "px");
	$('.pub').css('top', ($(this).scrollTop()+($(document).height()/2-200)) + "px");
});



function checkArrow()
{
	if(currpage==0)
		$(".prec").fadeOut('fast');
	else
		$(".prec").fadeIn('fast');
		
	if(currpage==nbpage-1)
		$(".suiv").fadeOut('fast');
	else
		$(".suiv").fadeIn('fast');
}

function gotoPage()
{
	checkArrow();
	n=currpage;
	var item=n*(nbcbp);
	$(".mask_choco").scrollTo($("#choc_"+item),800,{axis:'x'});
}
