/*
    CARROUSEL JS
*/


var carrousel = {
    
    nbSlide : 0,
    nbCurrent : 1,
    elemCurrent : null,
    elem : null,
    timer : null,
    
    init : function(elem){
        this.nbSlide = elem.find(".slide").length;
        
        // 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(){ carrousel.gotoSlide($(this).text()); })
        
        // Initialisation du carrousel
        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");
        
        // On cré le timer
        carrousel.play();
        // Stop quand on passe dessus
        elem.mouseover(carrousel.stop);
        elem.mouseout(carrousel.play);
    },
    
    gotoSlide : function(num){
        if(num==this.nbCurrent){ return false; }
        
        /* Animation en fadeIn/fadeOut*/
        this.elemCurrent.fadeOut();
        this.elem.find("#slide"+num).fadeIn();
        
        /* 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() };
        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.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 span").removeClass("active");
        this.elem.find(".navigation span:eq("+(num-1)+")").addClass("active");
        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(carrousel.timer);
    },
    play : function(){
        window.clearInterval(carrousel.timer);
        carrousel.timer = window.setInterval("carrousel.next()",5000);
    }

}

var carrousel_jeu = {
    
    nbSlide : 0,
    nbCurrent : 1,
    elemCurrent : null,
    elem : null,
    timer : null,
    
    init : function(elem){
        this.nbSlide = elem.find(".slide_jeu").length;
        
        // Créer la pagination
        elem.append('<div class="navigation_jeu"></div>');
        for(var i=1;i<=this.nbSlide;i++){
            elem.find(".navigation_jeu").append("<span>"+i+"</span>");
        }
        elem.find(".navigation_jeu span").click(function(){ carrousel_jeu.gotoSlide($(this).text()); })
        
        // Initialisation du carrousel_jeu
        this.elem=elem;
        elem.find(".slide_jeu").hide();
        elem.find(".slide_jeu:first").show();
        this.elemCurrent = elem.find(".slide_jeu:first");
        this.elem.find(".navigation_jeu").css("opacity",0.6);   // On rend la navigation opaque
        this.elem.find(".navigation_jeu span:first").addClass("active");
        
        // On cré le timer
        carrousel_jeu.play();
        // Stop quand on passe dessus
        elem.mouseover(carrousel_jeu.stop);
        elem.mouseout(carrousel_jeu.play);
    },
    
    gotoSlide : function(num){
        if(num==this.nbCurrent){ return false; }
        
        /* Animation en fadeIn/fadeOut*/
        this.elemCurrent.fadeOut();
        this.elem.find("#slide_jeu"+num).fadeIn();
        
        /* 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() };
        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.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_jeu span").removeClass("active");
        this.elem.find(".navigation_jeu span:eq("+(num-1)+")").addClass("active");
        this.nbCurrent = num;
        this.elemCurrent = this.elem.find("#slide_jeu"+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(carrousel_jeu.timer);
    },
    play : function(){
        window.clearInterval(carrousel_jeu.timer);
        carrousel_jeu.timer = window.setInterval("carrousel_jeu.next()",5000);
    }

}

var carrousel_jouet = {
    
    nbSlide : 0,
    nbCurrent : 1,
    elemCurrent : null,
    elem : null,
    timer : null,
    
    init : function(elem){
        this.nbSlide = elem.find(".slide_jouet").length;
        
        // Créer la pagination
        elem.append('<div class="navigation_jouet"></div>');
        for(var i=1;i<=this.nbSlide;i++){
            elem.find(".navigation_jouet").append("<span>"+i+"</span>");
        }
        elem.find(".navigation_jouet span").click(function(){ carrousel_jouet.gotoSlide($(this).text()); })
        
        // Initialisation du carrousel_jouet
        this.elem=elem;
        elem.find(".slide_jouet").hide();
        elem.find(".slide_jouet:first").show();
        this.elemCurrent = elem.find(".slide_jouet:first");
        this.elem.find(".navigation_jouet").css("opacity",0.6);   // On rend la navigation opaque
        this.elem.find(".navigation_jouet span:first").addClass("active");
        
        // On cré le timer
        carrousel_jouet.play();
        // Stop quand on passe dessus
        elem.mouseover(carrousel_jouet.stop);
        elem.mouseout(carrousel_jouet.play);
    },
    
    gotoSlide : function(num){
        if(num==this.nbCurrent){ return false; }
        
        /* Animation en fadeIn/fadeOut*/
        this.elemCurrent.fadeOut();
        this.elem.find("#slide_jouet"+num).fadeIn();
        
        /* 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() };
        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.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_jouet span").removeClass("active");
        this.elem.find(".navigation_jouet span:eq("+(num-1)+")").addClass("active");
        this.nbCurrent = num;
        this.elemCurrent = this.elem.find("#slide_jouet"+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(carrousel_jouet.timer);
    },
    play : function(){
        window.clearInterval(carrousel_jouet.timer);
        carrousel_jouet.timer = window.setInterval("carrousel_jouet.next()",5000);
    }

}

$(function(){
    carrousel.init($("#carrousel"));
	carrousel_jeu.init($("#carrousel_jeu"));
	carrousel_jouet.init($("#carrousel_jouet"));
});
