$(window).ready(function()
{

	$('#main').css({opacity:'1'});
	
	nbelem=5;
	nbpage=Math.ceil($("#slide_bloc .middle li").length/nbelem);
	currpage=1;
	sens=1;
	//setInterval("autopage()", 6000);
	$(".bgfield, .bgtextarea ").css('opacity',0.5);
	$(".bgfield input, .bgtextarea textarea").focus(function()
	{
		$(this).stop();
		$(this).parent('.bgfield, .bgtextarea').animate({'opacity':0.7},300);	
	});
	$(".bgfield input, .bgtextarea textarea").blur(function()
	{
		$(this).stop();
		$(this).parent('.bgfield, .bgtextarea').animate({'opacity':0.5},300);	
	});
	
	$("#gotoleft").click(function()
	{
		currpage--;
		if(currpage<1)
			currpage=1;
			changepage();		
	});
	$("#gotoright").click(function()
	{
		currpage++;
		if(currpage>nbpage)
			currpage=nbpage;
			changepage();
	});
	
	
	$().mousemove(function(e){
      //$('#status').html(e.pageX +', '+ e.pageY);
	  mouseX=e.pageX-$('#bubule').width()-30;
	  mouseY=e.pageY-45;
	  $("#bubule").css('top',mouseY);
	  $("#bubule").css('left',mouseX);
	});
	$("#bubule").css({opacity:'0.8'});
	$(".bubulepop").mouseover(function()
	{
		$("#bubule").html($(this).attr('alt'));
		//$("#bubule").stop();
		$("#bubule").slideDown(150)
	});
	
	$(".bubulepop").mouseout(function()
	{
		//$("#bubule").stop();
		$("#bubule").fadeOut(100)
	});
	
	$(".error").mouseover(function()
	{
		$("#bubule").html($(this).attr('title'));
		//$("#bubule").stop();
		$("#bubule").slideDown(150)
	});
	
	$(".error").mouseout(function()
	{
		//$("#bubule").stop();
		$("#bubule").fadeOut(100)
	});

});

function autopage()
{
	currpage+=sens;
	if(currpage==nbpage)
		sens=-1;
	if(currpage==1)
		sens=1;

	changepage();
}


function changepage()
{
	gotoelem=$("#slide_bloc .middle li").get((currpage-1)*nbelem);
	$("#slide_bloc .middle").scrollTo(gotoelem,1000,{axis:'x',margin: true});
}
