/****
 * Titre : Diaporama
 * Auteur : Fabien Evain
 * Email : naonak@free.fr
 * Url : -
 * Description : Permet de créer un Diaporama dynamique.
****/
function Diaporama(imageName,image_tab, imageZoom_tab, duration) {
  this.current = 0;
  this.imageName = imageName;
  this.mode = 0;
  this.timer = null;
  this.image_tab=image_tab;
  this.imageZoom_tab=imageZoom_tab;
  this.duration=duration;
  eval(this.obj + "=this");
}

Diaporama.prototype.imgpreload=imgpreload;
Diaporama.prototype.next=next;
Diaporama.prototype.previous=previous;
Diaporama.prototype.first=first;
Diaporama.prototype.last=last;
Diaporama.prototype.autoPlay=autoPlay;
Diaporama.prototype.rotate=rotate;
Diaporama.prototype.zoom=zoom;
Diaporama.prototype.affichePhoto=affichePhoto;


function imgpreload(){
  var imgpreload=new Array();
  for (i=0;i<=this.image_tab.length-1;i++){
    imgpreload[i]=new Image();
    imgpreload[i].src=this.image_tab[i];
  }
}
function next(){ // forward one image
  if(this.image_tab[this.current+1]){
    this.current++;
    document.images[this.imageName].src=this.image_tab[this.current];
  }else{this.first();}
}

function previous(){ // back on image
  if((this.current-1) >= 0){
    this.current--;
    document.images[this.imageName].src=this.image_tab[this.current];
  }else{this.last();}
}

function first(){ // jump to first image
  this.current=0;
  document.images[this.imageName].src=this.image_tab[this.current];

}

function last(){ // this is jump to last image
  this.current=(this.image_tab.length-1);
  document.images[this.imageName].src=this.image_tab[this.current];
}
function autoPlay(ap) {
  if(!ap && this.mode){
    this.mode=0;
    this.rotate();
  }else if(ap && !this.mode){
    this.mode=1;
    this.rotate();
  }
}
function rotate() {
  if (this.mode == 1) {
    this.current = (this.current == this.image_tab.length-1) ? 0 : this.current+1;
    document.images[this.imageName].src = this.image_tab[this.current];
    this.timer = setTimeout(this.obj + ".rotate()", this.duration);
  } else {
    clearTimeout(this.timer);
    this.timer = null;
  }
}
function zoom() {
 this.affichePhoto(this.imageZoom_tab[this.current]);
}
function affichePhoto(img) {
	var titre="Nom de votre Magasin";
	w=open("",'image','width=220,height=75,toolbar=no,scrollbars=no,resizable=yes');	
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

