tailletotale = 0;
direction = "left";
stopscroll = false;

$(document).ready(function() {
	
	// Placement des thumbs	
	$("#scroll>li").each(function() {
	  var left = tailletotale;
  	tailletotale = tailletotale + parseInt($(this).css('width')) + parseInt($(this).css('padding-left')) + parseInt($(this).css('padding-right')) + parseInt($(this).css('border-left-width')) + parseInt($(this).css('border-right-width'));
	  $(this).css('left',left+'px');
	});
	
	$("#scroll").mouseover(function(){
		stopscroll	=	true;
	});
	
	$("#scroll").mouseout(function(){
		stopscroll	=	false;
	});
	
	$("#right").click(function(){
		direction = "left";
		stopscroll	=	false;
		return false;
	});
	
	$("#left").click(function(){
		direction = "right";
		stopscroll	=	false;
		return false;
	});
	
	$("#pause").click(function(){
		stopscroll = !stopscroll;
	});

	if($("#scroll>li").length > 6){
		Defil();
	}
	
	// SEO
	$('#infosite li.copyright a').click(function(){
	    $('#seo_index').toggle();
	    return false;
	});
	
	
});

function Defil()
{
	if(!stopscroll){
		$("#scroll>li").each(function() {
			var posleft = parseInt($(this).css('left'));
			var width =  parseInt($(this).css('width')) + parseInt($(this).css('padding-left')) + parseInt($(this).css('padding-right')) + parseInt($(this).css('border-left-width')) + parseInt($(this).css('border-right-width'));
			
			// scroll vers la gauche	
			if(direction == 'left'){
				if(posleft <= -width) {
     			var width_next	=	parseInt($('#scroll>li:first').next().css('width')) + parseInt($('#scroll>li:first').next().css('padding-left')) + parseInt($('#scroll>li:first').next().css('padding-right')) + parseInt($('#scroll>li:first').next().css('border-left-width')) + parseInt($('#scroll>li:first').next().css('border-right-width'));
		      $(this).remove().clone().insertAfter("#scroll>li:last").css('left',tailletotale - width - width_next  +'px');
		    }
       
	     	$(this).animate({ 
	       	left: (posleft - width)+'px'
	     	}, 600 );
	     	
	    // scroll vers la droite
	    }else if(direction == 'right'){
	     	
	    	if(posleft >= tailletotale - width) {
		      var objet = $(this).remove().clone().insertBefore("#scroll>li:first");
		      objet.css('left', '-'+ width +'px');
		      objet.animate({ 
	       		left: (parseInt(objet.css('left')) + width)+'px'
	     		}, 600 );
		    }else{
		    	$(this).animate({ 
	       		left: (posleft + width)+'px'
	     		}, 600 );
		    }
	    }
    });
	}
	window.setTimeout(function() {Defil()},3000);
}