/**
 * myScroll
*/


var myScroll = {
    nbbreve : 0,
    nbCurrent :1,
    elemCurrent : null,
    elem : null,
    timer : null,
    breveTimer : null,
    
    init : function (elem){
        this.nbbreve = elem.find('.textebreves').length;
        
       // initialisation carrousel
       this.elem=elem;
       elem.find('.textebreves').hide();
       elem.find('.textebreves:first').show();
       this.elemCurrent=elem.find('.textebreves:first');
        
       // Démarrage du mode automatique
       myScroll.play();      
        
        // stop au survol de souris       
        this.elem.mouseover(myScroll.stop);
        this.elem.mouseout(myScroll.play);
    },

    gotobreve : function (num){
        if(num==this.nbCurrent) {return false;}
        var breveToGo = this.elem.find('#breve'+num);
        /* Animation de base (Fade)
        this.elemCurrent.fadeOut();
        this.elem.find('#breve'+num).fadeIn();
       */
        
        /* Animation par Glissement */
        //var sens = 1;
        //if(num<this.nbCurrent){sens = -1};
        //var breveHeight=sens*(breveToGo.height()); 
        
        var animationSpeed = 5000;
        var breveHeight=this.elemCurrent.height();
        var cssDep = { "top" : breveHeight};
        var cssFin = { "top" : - breveHeight};
        breveToGo.css(cssDep).fadeIn(800);

        breveToGo.animate({"top":0 , "left":0},animationSpeed);
        this.elemCurrent.animate(cssFin,animationSpeed,function(){$(this).hide()});
        
        /* FIN - Animation par Glissement */
        
        /* Gestion de la Nav */
        this.nbCurrent=num;
        this.elemCurrent=breveToGo;
    },

    
     next : function () {
        var num = this.nbCurrent+1;
        if(num>this.nbbreve){
            num=1;
            }
        this.gotobreve(num);        
    },
    
     prev : function () {
        var num = this.nbCurrent-1;
        if(num<1){
            num=this.nbbreve;
            }
        this.gotobreve(num);        
    },
    
    play : function (){
        window.clearInterval(myScroll.timer);
        myScroll.timer = window.setInterval('myScroll.next()',7500);
    },
    
    stop : function(){
        window.clearInterval(myScroll.timer);
    }
    
};

$(function(){
    myScroll.init($('#brevesdefil_conteneur'));
});
