var InfoDev = {
   /*
    *
    * Dépendances : Mootools 1.2
    * Auteur : Steven TITREN   -   stitren@ekinoxe.fr
    *
    * Ce fichier est la propriété de la société Ekinoxe ORIGIN - www.ekinoxe.fr
    * Ce fichier n'est en aucun cas libre de droit, vous n'avez pas l'autorisation de 
    * le diffuser ou de le réutiliser dans un projet exterieur.
    *
    */
    'auteur'  : 'Steven Titren',
    'email'   : 'stitren@ekinoxe.fr'
}

var pubSlide = new Class({
   
  options : {
    width :'100px',
    duration : 700, // en milliseconde
    delayAuto : 5, // en seconde
    transition: Fx.Transitions.Cubic.easeInOut,
    classActive : 'active'
  },
  
  count : 0,
  
  initialize : function(element, options) {
    this.setOptions(options);
    this.el = $(element);
    this.elButton = $$('#'+element + ' div.button')[0];
    this.elPub = $$('#'+element + ' div.overflow')[0];
    
    if(typeof this.el != "undefined" && typeof this.elButton != "undefined" && typeof this.elPub != "undefined"){
      
      this.slider = new Fx.Morph(this.elPub, {duration: this.options.duration, transition: this.options.transition});
      
      var nbPub = this.elPub.getElements('div.pub_div').length;
      var as = new Array();

      for(i=1; i<=nbPub; i++){
        var a = new Element('a').set('html', i);
        a.setProperties({'rel':i-1, 'href':'#'});
        this.elButton.adopt(a);
      }
      
      var as = this.elButton.getElements('a');
      var i=0;
      
      
      if(as.length>0){
      	
        as[0].addClass(this.options.classActive);
        
        as.each(function(a){
          
          $(a).addEvent('click', function(){
            clearInterval(this.timer);
            
            setTimeout(this.changeAuto.bind(this), this.options.delayAuto * 2 * 1000)
            
            this.changePub(a);
            
            as.removeClass(this.options.classActive);
            a.addClass(this.options.classActive);
            
            return false;
          }.bind(this));
          
          i++;
        }.bind(this));
        
        this.changeAuto();
      
      }
    }
  },
  
  changeAuto : function(){
    var as = this.elButton.getElements('a');
    var nbPub = as.length;
    var mult = 1;
    
    this.timer = setInterval(function(){
      if(this.count>=nbPub-1) mult = -1;
      if(this.count<=0) mult = 1;
      
      this.count = this.count.toInt() + (1*mult);
      
      //console.log(this.count);
      as.removeClass(this.options.classActive);
      as[this.count].addClass(this.options.classActive);
      
      this.changePub(as[this.count]);
      
    }.bind(this), this.options.delayAuto * 1000);
    
  },
  
  changePub : function(a){
    var numPub = a.getProperty('rel');
    this.count = numPub;
    var marginLeft =  -1*(numPub * this.options.width)
    
    this.slider.start({
      'margin-left' : marginLeft
    });
  }
  
})
pubSlide.implement(new Options, new Events);