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

function fadeshow(){
	var index = 2,max_div = 1,speed;
	this.actif = null;
	
	this.init = function(sp) {   
		speed = sp || 2000;
		$("#SlideShow .inner2 div").slice(1).hide();
		max_div = $("#SlideShow .inner2 div").length;
		if(max_div == 1 ) return ;
		for(var j = 1; j <= max_div; j+=1) {
			var id = 'id' + j;
			$("#SlideShow .inner2 div").eq(j-1).attr("id",id);
		}   
		timer();   
		$("#colonne3").hover(
			function () {
				setStop();           
			},
			function () {
				timer();				
			}
		);   
		
	   $("#SlideShow #menuFaitsActu li").bind('click',function(event){
			//console.log($(this).find("a").text());
			event.stopPropagation();
			event.preventDefault();
			var n = parseInt($(this).find("a").text());
			if(n != (index-1)) { 
				setStart(n);
				index = index + 1;
			}
	   });
	  
	   $(window).unload( function () { 		
			setStop();
		} );			
	   
	} ;
	
	function timer () {		
		this.actif = setTimeout(function(){setAuto();}, speed);
	}
	
	function setAuto() {
		if(index > max_div) {index = 1;}
		//console.log("index in setAuto = " + index);
		setStart(index);
		index+=1;
		timer () ;
	}
	
	function setStart(n) {
		//console.log("i in timer __ _ _ _ " +index);
		var id = 'id' + n ;   
		$("#SlideShow .inner2 div").hide();
		$("#SlideShow .inner2 div#"+id).fadeIn(500);   
		$("#SlideShow  #menuFaitsActu li").removeClass("gray");
		$("#SlideShow  #menuFaitsActu li").eq(parseInt(n)-1).addClass("gray");
		index = parseInt(n);
	}
	
	function setStop(){
		clearTimeout(this.actif);
		this.actif = null;
	}
	
}


$(document).ready(function() {   
    var myfadeshow = new fadeshow(); 
	myfadeshow.init(10000);
});

