$(document).ready(function() {
	$("#cover .vignette:first").addClass("active");
	$active = $("#cover .vignette:first");
	$desactif = $("#cover .vignette:last"); 
	$total = $desactif;
	$("#cover .vignette").click(function() {
		$desactif = $active;
		$active = $(this);
		
		clearInterval(play); 
		rotate(); 
		rotateSwitch(); 
		return false;
	});
	rotateSwitch = function(){
		play = setInterval(function(){ 
			$desactif = $active;
			if ($active.attr("rel")+1 > $total){
				$active = $("#cover #vignette0"); 
			}else{
				$active = $("#cover #vignette"+(Number($active.attr("rel"))+1));
			}
			rotate();
		}, 7000); 
	};
	rotate = function(){
			if ( $active.length === 0) { 
				$active = $("#cover .vignette:first");
				$desactif = $("#cover .vignette:last"); 
			}
			$("#slide"+$desactif.attr("rel")).fadeOut("slow");
			$("#cover .vignette").removeClass("active"); 
			$active.addClass("active");
			$("#slide"+$active.attr("rel")).fadeIn("slow");
	};
	rotateSwitch(); 
	
	
	var nbcover = $('#pubmag').children().size();
	var coveractif = 0;
	var coverdesactif = coveractif;
	rotatecover = function(){
		coverplay = setInterval(function(){ 
			coverdesactif = coveractif;
			if(coveractif < (nbcover-1)){coveractif++;}else{coveractif=0;}
			$("#pubmag .mag"+coveractif).fadeIn();
			$("#pubmag .mag"+coverdesactif).fadeOut();
		}, 7000); 
	};
	if(nbcover > 1){rotatecover();}
	
});
