/**
* author : Smart Agence
  -- [respecter les structures cote html en utilisant ce script ... : ) ]
*/

function fadeshowAlternate(){
	var index = 1, max_div = 3, speed = 2000;
	this.actif = null;
	
	this.init = function(sp) {  
		if( $("#fadeShow").length <= 0 ) return ;
		speed = sp || 2000;			
		$("#fadeShow  div.fadeBloc").slice(1).hide();
		
		/*____________ [ set id for each bloc] __________________*/
		for(var j = 0; j < max_div; j+=1) {
			var id = 'id' + j;
			$("#fadeShow  div.fadeBloc").eq(j).attr("id",id);
		}   
		
		reactif();												   
		timer(); 
		
		$("#menuFaitsActu a").bind('click',function(event){
			event.stopPropagation();
			event.preventDefault();
			var n =  $("#menuFaitsActu a").index(this);
			if(n != (index-1)) { 
				setStart(n);
				index = index + 1;
			}			
		});
		
		$(window).unload( function () { 		
				setStop();
				desactif();
			} );			   
	};	
	
	function reactif(){	
		$("#fadeShow").bind("mouseover",function () {
				setStop();           
			});
		$("#fadeShow").bind("mouseout",function () {
				timer();           
			});
	}	
	
	function desactif(){			
		$("#fadeShow").unbind("mouseout");
	}	
	
	function timer () {	
		setStop();
		this.actif = setTimeout(function(){setAuto();}, speed);
	}	
	
	function setAuto(){
		if(index >= max_div) {index = 0;}
		setStart(index);
		index+=1;
		timer() ;
	}
	
	function setStart(n) {
		var id = 'id' + n ;   
		$("#fadeShow div.fadeBloc:visible").css("display","none");
		$("#fadeShow  div#"+id).fadeIn(1000); 
		upDateMenu(n);	
		index = parseInt(n);
	}
	
	function upDateMenu(n){			
		$("#menuFaitsActu a").addClass("off").removeClass("on");
		$("#menuFaitsActu a:eq("+n+")").addClass("on").removeClass("off");
	}
	
	function setStop(){
		clearTimeout(this.actif);
		this.actif = null;
	}	
}

jQuery(document).ready(function($) {   
    var myfadeshow = new fadeshowAlternate(); 
	myfadeshow.init(8000);
});


