

var carrousel_head = {
	nbSlide:0,
	nbCurrent:1,
	elemCurrent:null,
	elem:null,
	timer:null,
	
	init:function(elem){
		this.nbSlide=elem.find(".slide_head").length;
		
		elem.append('<div class="navigation"></div>');
		

		this.elem=elem;
		elem.find(".slide_head").hide();
		elem.find(".slide_head:first").show();
		this.elemCurrent=elem.find(".slide_head:first");
		this.elem.find(".navigation span:first").addClass("active");
		this.elem.find(".navigation").css("opacity",0.6);
		
		carrousel_head.play();
		elem.mouseover(carrousel_head.stop);
		elem.mouseout(carrousel_head.play);
	},
		
	gotoSlide:function(num){
		if(num==this.nbCurrent){return false;}
		this.elemCurrent.find(".visu_head").fadeOut();
		this.elem.find("#slide_head"+num).show();
		this.elem.find("#slide_head"+num+" .visu_head").hide().fadeIn();
		
		
		this.elem.find(".navigation span").removeClass("active");
		this.elem.find(".navigation span:eq("+(num-1)+")").addClass("active");
		this.nbCurrent=Math.floor(Math.random() * this.nbSlide+1);
		
		this.elemCurrent=this.elem.find("#slide_head"+num);
	},
				
	next:function(){
		var num=this.nbCurrent+1;
		var random=Math.floor(Math.random() * this.nbSlide)+1
		if(num>this.nbSlide){num=random;}
		this.gotoSlide(num);
	},
		
		
	stop:function(){
		window.clearInterval(carrousel_head.timer);
	},
		
	play:function(){
		window.clearInterval(carrousel_head.timer);
		carrousel_head.timer=window.setInterval("carrousel_head.next()",3000);
	}
}

$(function(){
	carrousel_head.init($("#carrousel_head"));
});