/*
    CARROUSEL JS
*/


var fcarrousel = {
    
    nbFslide : 0,
    nbCurrent : 1,
    elemCurrent : null,
    elem : null,
    timer : null,
    
    init : function(elem){
        this.nbFslide = elem.find(".fslide").length;
        
        
        // Initialisation du carrousel
        this.elem=elem;
        elem.find(".fslide").hide();
        elem.find(".fslide:first").show();
        this.elemCurrent = elem.find(".fslide:first");
        
        // On cré le timer
        fcarrousel.play();
        // Stop quand on passe dessus
        elem.mouseover(fcarrousel.stop);
        elem.mouseout(fcarrousel.play);
    },
    
    gotoFslide : function(num){
        if(num==this.nbCurrent){ return false; }
        

        /* Animation en slide 
	*/
        var cssDeb = { "top" : this.elem.height() };
        var cssFin = { "top" : -this.elem.height() };
        this.elem.find("#fslide"+num).show().css(cssDeb);
        this.elem.find("#fslide"+num).animate({"top":0,"left":0},500);
        this.elemCurrent.animate(cssFin,500);
     
        this.nbCurrent = num;
        this.elemCurrent = this.elem.find("#fslide"+num);
    },
    
    next : function(){
        var num  = this.nbCurrent+1;
        if(num  >this.nbFslide){
            num  = 1;
        }
        this.gotoFslide(num);
    },
    prev : function(){
        var num  = this.nbCurrent-1;
        if(num< 1){
            num= this.nbFslide;
        }
        this.gotoFslide(num);
    },
    stop : function(){
        window.clearInterval(fcarrousel.timer);
    },
    play : function(){
        window.clearInterval(fcarrousel.timer);
        fcarrousel.timer = window.setInterval("fcarrousel.next()",5000);
    }

}

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