function Diaporama (ObjectName,TableName,Images,Directory){
	this.ObjectName	= ObjectName; // Nom de l objet javascript pour le timer
	this.TableName	= TableName; // Nom du tableau dans lequel le background va changer
	this.CurID		= -1;
	this.Images 	= Images; // tableau de nom de fichiers
	this.TimerId 	= 0;
	this.Directory 	= Directory; // repertoire ou sont situé les fichiers
	this.TimerLenght= 2500; // temps entre 2 diapos


	
	this.StopStart = function(){
		this.Stop();
		this.Start();
	};
	this.StartRandom = function(){
		if (this.TimerId>0)
			window.clearTimeout(this.TimerId);
		this.CurID = randomnumber=Math.floor(Math.random()*this.Images.length)
		//this.CurID += 1;
		if (this.CurID == this.Images.length) this.CurID = 0;
		this.ChangeImage(this.CurID);
		this.TimerId = setTimeout(ObjectName+".Start()", this.TimerLenght );
	};
	this.Start = function(){
		if (this.TimerId>0)
			window.clearTimeout(this.TimerId);
		this.CurID += 1;
		if (this.CurID == this.Images.length) this.CurID = 0;
		this.ChangeImage(this.CurID);
		this.TimerId = setTimeout(ObjectName+".Start()", this.TimerLenght );
	};
	this.StartPrev = function(){
		if (this.TimerId>0)
			window.clearTimeout(this.TimerId);
		this.CurID -= 1;
		if (this.CurID < 0) this.CurID = ( this.Images.length-1);
		this.ChangeImage(this.CurID);
		this.TimerId = setTimeout(ObjectName+".StartPrev()", this.TimerLenght );
	};
	this.Stop = function(){
	   	if(this.TimerId) {
	      	window.clearTimeout(this.TimerId);
	      	this.TimerId  = 0;
	      	this.CurID = 0;
	  		this.ChangeImage(this.CurID);
		}
	};
	this.Pause = function(){
	   if(this.TimerId) {
	      window.clearTimeout(this.TimerId);
	      this.TimerId = 0;
	   }
	};
	this.ChangeImage = function(ID){
		curdiaporama = document.getElementById(this.TableName);
		curdiaporama.style.background="url("+this.Directory+this.Images[ID]+") no-repeat center center";
		this.setInformationTexte();
	};
	
	this.setInformationTexte = function(){
		if (Informations = document.getElementById("Information"+this.TableName)){
			//Informations.innerHTML=ObjectName+".Start(TimerId:"+this.TimerId+") this.Images["+this.CurID+"/"+this.Images.length+"] => "+this.Directory+this.Images[this.CurID];
			Informations.innerHTML="["+(this.CurID+1)+"/"+(this.Images.length)+"]";
		}
	}
}


function DiaporamaIMGResized(ObjectName, ElementId, Images, Directory, Timer, MaxWidth, MaxHeight){
	this.ObjectName	= ObjectName; // Nom de l objet javascript pour le timer
	this.ElementId 	= ElementId;
	this.CurID		= -1;
	this.Images 	= Images; // tableau de nom de fichiers
	this.TimerId 	= 0;
	this.Directory 	= Directory; // repertoire ou sont situé les fichiers
	this.TimerLength= Timer; // temps entre 2 diapos 2500
	this.MaxWidth 	= MaxWidth; //218
	this.MaxHeight 	= MaxHeight; //200


	/*var j = 0;
	var p = this.Images.length;
	
	var preLoad = new Array()
	for (i = 0; i < p; i++){
		preLoad[i] = new Image()
		preLoad[i].src = this.Directory+this.Images[i][0]
	}*/
	
	this.StopStart = function(){
		this.Stop();
		this.Start();
	};
	this.Start = function(){
		if (this.TimerId>0)
			window.clearTimeout(this.TimerId);
		this.CurID += 1;
		if (this.CurID == this.Images.length) this.CurID = 0;
		this.ChangeImage(this.CurID);
		this.TimerId = setTimeout(ObjectName+".Start()", this.TimerLength );
	};
	this.Stop = function(){
	   	if(this.TimerId) {
	      	window.clearTimeout(this.TimerId);
	      	this.TimerId  = 0;
	      	this.CurID = 0;
	  		this.ChangeImage(this.CurID);
		}
	};
	this.Pause = function(){
		 if(this.TimerId) {
	      window.clearTimeout(this.TimerId);
	      this.TimerId = 0;
	   }
	};
	this.Popup = function(){
		//simplePopup(this.Directory+"fullsize/"+this.Images[this.CurID][0]);
		popupImageGoodSize(this.Directory+"fullsize/"+this.Images[this.CurID][0], "Zoom");
	};
	this.ChangeImage = function(ID){
		curdiaporama = document.getElementById(this.ElementId);
        curdiaporama.src=this.Directory+this.Images[ID][0];
 			
		this.setInformationTexte();
		resizeImage(curdiaporama, this.Images[ID][1], this.Images[ID][2], this.MaxWidth, this.MaxHeight);
	};

	this.setInformationTexte = function(){
		if (Informations = document.getElementById("Information"+this.TableName)){
			Informations.innerHTML="["+(this.CurID+1)+"/"+(this.Images.length)+"]";
		}
	}
}

	function resizeImage(imageObject, imageWidth, imageHeight, maxWidth, maxHeight){
		// Initialisation
		imageObject.width = imageWidth;
		imageObject.height = imageHeight;
		
		// Calcul du coefficient de réduction
		if(maxWidth>0 && maxHeight>0) {
			var coeffW = maxWidth / imageWidth;
			var coeffH = maxHeight / imageHeight;
			var coeff = coeffW;
			if(coeffH<coeffW)
				coeff=coeffH;
		} else if(maxWidth>0) {
			var coeff = maxWidth / imageObject.width;
		} else if(maxHeight>0) {
			var coeff = maxHeight / imageObject.height;
		}
		
		// Réduction seulement
		if(coeff<1) {
			imageObject.width = imageWidth * coeff;
			imageObject.height = imageHeight * coeff;
		}
	};


