// JavaScript Document
/*
    carrouselC JS
*/


var carrouselC = {
    
    nbSlide : 0,
    nbCurrent : 1,
    elemCurrent : null,
    elem : null,
    timer : null,
    
    init : function(elem){
        this.nbSlide = elem.find(".slideC").length;
               
        // Initialisation du carrouselC
        this.elem=elem;
        elem.find(".slideC").hide();
        elem.find(".slideC:first").show();
        this.elemCurrent = elem.find(".slideC:first");
        
        // On cré le timer
        carrouselC.play();
        // Stop quand on passe dessus
        elem.mouseover(carrouselC.stop);
        elem.mouseout(carrouselC.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(".visuC").fadeOut();
        $(".slideC").fadeOut();
        this.elem.find("#slideC"+num).show();

        currentHeight = $("#slideC"+num+" img").height();
        currentWidth = $("#slideC"+num+" img").width();
        if(currentHeight != 0) {
            diffHeight = (84-parseInt(currentHeight))/2;
            if(diffHeight != 0) { $("#slideC"+num).css('top',diffHeight); }
        }
        if(currentWidth != 0) {
            diffWidth = (160-parseInt(currentWidth))/2;
            if(diffWidth != 0) { $("#slideC"+num).css('left',diffWidth); }
        } 

        this.elem.find("#slideC"+num+" .visuC").hide().fadeIn(2000);
        //*/
		
        
        this.nbCurrent = num;
        this.elemCurrent = this.elem.find("#slideC"+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(carrouselC.timer);
    },
    play : function(){
        window.clearInterval(carrouselC.timer);
        carrouselC.timer = window.setInterval("carrouselC.next()",7000);
    }

}

$(function(){
    carrouselC.init($("#diapoCompo"));
	$('#slideC1').show(); 
	$('.visuC').show();

    currentHeight = $("#slideC1 img").height();
    currentWidth = $("#slideC1 img").width();

    diffHeight = ((84-parseInt(currentHeight))/2);
    if(diffHeight != 0) { $("#slideC1").css('top',diffHeight); }

    diffWidth = (160-parseInt(currentWidth))/2;
    if(diffWidth != 0) { $("#slideC1").css('left',diffWidth); }

});
