

/* classe DIAPORAMA
          V1.02 - 04/07/06
*/

function Diaporama(id,nombre, repertoire, vitesse) {
       this.laphoto= 1;
       this.clic= 0;
       this.photos= null;
       this.id= id
       this.vitesse= (vitesse>0) ? vitesse : 3000;
       this.init(nombre,repertoire)

}

/* définition des méthodes */

Diaporama.prototype= {
   background: false,
   
   getImg: function(){
      if (this.clic>0) window.clearTimeout(this.clic)
      return getElement(this.id)
   },

   affImg: function(element){
	        if (element.filters) if (element.filters.length>0) element.filters(0).Apply();
	        var s=this.photos[this.laphoto].src;
	        if (this.background)
              element.style.backgroundImage ='url('+s+')'
           else
              element.src =s
           if (element.filters) if (element.filters.length>0) element.filters(0).Play();
   },
   
    incImage: function() {
             var element = this.getImg();
             this.laphoto++; if (this.laphoto==this.photos.length) { this.laphoto=1 }
             this.affImg(element)
               },
   
   decImage: function() {
             var element = this.getImg();
             this.laphoto--; if (this.laphoto<1) { this.laphoto=this.photos.length-1 }
             this.affImg(element)
              },
   
   incPhoto: function() {
             this.incImage()
             this.clic=window.setTimeout(this.id+'.incPhoto()', this.vitesse)
   },
   
   decPhoto: function() {
             this.decImage()
             this.clic=window.setTimeout(this.id+'.decPhoto()', this.vitesse)
   },
   
   init: function(nombre,repertoire) {
      if (nombre>0){
	      this.photos = new Array
	      for (var i=1; i<=nombre; i++){ this.photos[i] = new Image; this.photos[i].src = repertoire+''+i+'.jpg' }
      }
   },
   
   initArray: function(repertoire,images) {
      nombre = arguments.length; nombre--;
      if (nombre>0){
	      this.photos = new Array
	      for (var i=1; i<=nombre; i++){ this.photos[i] = new Image; this.photos[i].src = repertoire+''+arguments[i] }
      }
   },
   
   start: function(tempo) {
     tempo= (tempo>1) ? tempo : 1000
     if ((this.photos)&&(this.photos.length>0))
        //if ( this.getImg())
        this.clic=window.setTimeout(this.id+'.incPhoto()', tempo )
   }
};



function DiaporamaTxt(id,nombre, repertoire, vitesse) {
  this.parent=Diaporama;
  this.parent(id,nombre, repertoire, vitesse)
  this.setTxt = function() {
	   var element = getElement(this.id+'Txt')
      if (element) {
         var tmp = getElement(this.id+'Txt'+this.laphoto)
         if (tmp) element.innerHTML = tmp.innerHTML
      }
  }
}
DiaporamaTxt.prototype = new Diaporama ;
DiaporamaTxt.prototype.incPhoto= function() {
             var element = this.getImg();
             this.laphoto++; if (this.laphoto==this.photos.length) { this.laphoto=1 }
             this.affImg(element)
             this.clic=window.setTimeout(this.id+'.incPhoto()', this.vitesse)
             this.setTxt()
};

/*
<img src="exploitation/vigne/1.jpg" alt="" id="diapo"/>
<div id="diapoTxt">&nbsp;</div>
<div class="cache"><span id="diapoTxt1">1</span><span id="diapoTxt3">3</span><span id="diapoTxt4">4</span></div>
<script type="text/Javascript">
   var diapo = new DiaporamaTxt('diapo',5, 'exploitation/vigne/',6000)
       // diapo.background=true;
       diapo.start(3000)
OU :
   var diapo = new Diaporama('diapo',0, '',6000)
   diapo.initArray('../images/ph/','10.jpg','toto.jpg','2.jpg')
</script>
*/



