/*
    slideshow JS
*/

var slideshow = {
    
    nbSlide : 0,
    nbCurrent : 1,
    elemCurrent : null,
    elem : null,
    timer : null,
    
    init : function(elem){
        this.nbSlide = elem.find(".slide").length;

		// AJOUT
		//$("#slide1").fadeOut(3000);
		//$("#slide2").fadeIn(3000);
		/*
        elem.find("#slide1").fadeOut(3000);
        elem.find("#slide2").fadeIn(3000);
		*/
		//
		
		// Créer la pagination
        /*
		elem.append('<div class="navigation"></div>');
        for(var i=1;i<=this.nbSlide;i++){
            elem.find(".navigation").append("<span>"+i+"</span>");
        }
        */
        //elem.find(".navigation span").click(function(){ slideshow.gotoSlide($(this).text()); })
        elem.find(".navigation").mouseover(function(){ 
			//slideshow.gotoSlide($(this).text());
			slideshow.gotoSlide(this.id.substring(9));
			//alert(this.id.substring(9));
		})
		
        // Initialisation du slideshow
        //if(num == 1){
			this.elem=elem;
			elem.find(".slide").hide();
			elem.find(".slide:first").show();
			this.elemCurrent = elem.find(".slide:first");
			//this.elem.find(".navigation").css("opacity",0.6);   // On rend la navigation opaque
			//this.elem.find(".navigation span:first").addClass("active");
			this.elem.find(".navigation:first").addClass("slideshow_selected");
        //}
		
		// On créé le timer
        slideshow.play();
        // Stop quand on passe dessus
        elem.mouseover(slideshow.stop);
        elem.mouseout(slideshow.play);
    },
    
    gotoSlide : function(num){
        if(num==this.nbCurrent){ return false; }
        
        /*
		Animation en fadeIn/fadeOut 
		*/
		/*
		//this.elem.find("slide"+num).fadeIn();
        this.elem.find("#slide"+num).fadeIn(500);
        this.elemCurrent.fadeOut(500);
        */
		
		/* 
		Animation en slide
		*/ 
        /*
		var sens = 1;
        if(num<this.nbCurrent){ sens = -1;}
        //var cssDeb = { "left" : sens*this.elem.width() };
        //var cssFin = { "left" : -sens*this.elem.width() };
        var cssDeb = { "left" : sens*455 };
        var cssFin = { "left" : -sens*455 };
        this.elem.find("#slide"+num).show().css(cssDeb);
        this.elem.find("#slide"+num).animate({"top":0,"left":0},500);
        this.elemCurrent.animate(cssFin,500);
     	*/
		
        /*
        Animation Titre + Fadein/Out sur la div visu
        */
        ///*
        
		this.elemCurrent.fadeOut(500);
		//this.elemCurrent.find(".visu").fadeOut();

		this.elem.find("#slide"+num).show();
        
        this.elem.find("#slide"+num).fadeIn(500);
		//this.elem.find("#slide"+num+" .visu").hide().fadeIn();
        var titleHeight = this.elemCurrent.find(".title").height();
        this.elemCurrent.find(".title").animate({"top": titleHeight},500);
        this.elem.find("#slide"+num+" .title").css("top", 0).animate({"top": -titleHeight},500);
        //*/
        /*
		this.elemCurrent.find(".visu").fadeOut();
        this.elem.find("#slide"+num).show();
        this.elem.find("#slide"+num+" .visu").hide().fadeIn();
        var titleHeight = this.elemCurrent.find(".title").height();
        this.elemCurrent.find(".title").animate({"bottom": -titleHeight},500);
        this.elem.find("#slide"+num+" .title").css("bottom",-titleHeight).animate({"bottom": 0},500);
        */
		
        this.elem.find(".navigation").removeClass("slideshow_selected");
        this.elem.find(".navigation:eq("+(num-1)+")").addClass("slideshow_selected");

		this.nbCurrent = num;
		this.elemCurrent = this.elem.find("#slide"+num);
	},
    
    next : function(){
        var num  = this.nbCurrent+1;
        if(num  >this.nbSlide){
            num  = 1;
        }
        this.gotoSlide(num);
    },
    prev : function(){
        var num  = this.nbCurrent-1;
        if(num< 1){
            num= this.nbSlide;
        }
        this.gotoSlide(num);
    },
    stop : function(){
        window.clearInterval(slideshow.timer);
    },
    play : function(){
		window.clearInterval(slideshow.timer);
        slideshow.timer = window.setInterval("slideshow.next()",4000);
    }

}

$(document).ready(function(){
    slideshow.init($("#slideshow"));
});

