
// Constructeur

function tetiereSlide(aDiv1Name,aDiv2Name,aImageName,aImageAnimInSrcBase){
  this.div1 = document.getElementById(aDiv1Name); 
  this.div2 = document.getElementById(aDiv2Name);
  this.div1Name = aDiv1Name
  this.div2Name = aDiv2Name
  this.imageCoinId = aImageName
  this.imageCoin = document.getElementById(aImageName);
  this.imageAnimPreload = new Array()
  for(var x=0;x<6;x++){
    this.imageAnimPreload[x] = new Image()
    this.imageAnimPreload[x].src = aImageAnimInSrcBase + (x+1) + ".png"
  }
  this.imageOriginale = this.imageCoin.src
  this.div1OnMouseOut = this.div1.getAttribute("onMouseOut")
  this.pubAffichee = false
  this.timers = new Array()
  this.timers["onmouseover"] = new Array()
  this.timers["onmouseout"] = new Array()
  return this
}

// Nettoyage des timers en actions d'un groupe donné

tetiereSlide.prototype.clearTimers = function(aGroup){
  for(var x in this.timers[aGroup]){
    this.timers[aGroup][x].cancel()
  }
  this.timers = new Array()
  this.timers["onmouseover"] = new Array()
  this.timers["onmouseout"] = new Array()
}

// Ajout d'un timer sur un groupe donné

tetiereSlide.prototype.addTimer = function(aTimer,aGroup){
  this.timers[aGroup][this.timers[aGroup].length] = aTimer
  return aTimer
}

tetiereSlide.prototype.onRollOver = function(){
  if(this.pubAffichee) return
  this.clearTimers("onmouseover")
  this.clearTimers("onmouseout")
  this.imageCoin.src=this.imageAnimPreload[0].src
  CCallWrapper.asyncExecute(this.addTimer(new CCallWrapper(this,50,"afficheEtapeCoin",1),"onmouseover"))
  CCallWrapper.asyncExecute(this.addTimer(new CCallWrapper(this,100,"afficheEtapeCoin",2),"onmouseover"))
  CCallWrapper.asyncExecute(this.addTimer(new CCallWrapper(this,150,"afficheEtapeCoin",3),"onmouseover"))
  CCallWrapper.asyncExecute(this.addTimer(new CCallWrapper(this,200,"afficheEtapeCoin",4),"onmouseover"))
  CCallWrapper.asyncExecute(this.addTimer(new CCallWrapper(this,250,"afficheEtapeCoin",5),"onmouseover"))
  CCallWrapper.asyncExecute(this.addTimer(new CCallWrapper(this,300,"affichePub"),"onmouseover"))
  this.pubAffichee = true
}

// Permet d'afficher l'image du coin correspondante a une images donnée
// NB: Impossible d'utiliser les gifs animés a cause de la gestion IE 
// des gifs animés joués une seule fois au chargement.

tetiereSlide.prototype.afficheEtapeCoin = function(aEtape){
  this.imageCoin.src = this.imageAnimPreload[aEtape].src
}

// Affiche le div contenant la publicité et masque celui de la tétière

tetiereSlide.prototype.affichePub = function(){
  this.div1.setAttribute('onMouseOut','')
  this.div1.style.display = 'none'
  this.div2.style.display = 'block'
}

// Gestion de la sortie le la pub

tetiereSlide.prototype.onRollOut = function(id){
  CCallWrapper.asyncExecute(this.addTimer(new CCallWrapper(this,250,"doRollOut") ,"onmouseout"))
}

tetiereSlide.prototype.doRollOut = function(){
  this.imageCoin.src= this.imageOriginale
  this.div1.style.display = "block"
  this.div2.style.display = "none"
  this.div1.setAttribute('onMouseOut',this.div1OnMouseOut)
  this.pubAffichee = false
  
}
