/* classe DIAPORAMA			V1.03 - 03/11/08		*/

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;
			var img = getElement(this.id);
			img.setAttribute('title',tmp.innerHTML);
		}
	}
	this.setTxt();
}
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();
};
DiaporamaTxt.prototype.incImage= function(){
	var element = this.getImg();
	this.laphoto++; if (this.laphoto==this.photos.length) { this.laphoto=1; }
	this.affImg(element);
	this.setTxt();
};
DiaporamaTxt.prototype.decImage= function(){
	var element = this.getImg();
	this.laphoto--; if (this.laphoto<1) { this.laphoto=this.photos.length-1; }
	this.affImg(element);
	this.setTxt();
};

/*
<img src="../images/vin/1.jpg" alt="" id="diapo"/>
<p id="diapoTxt">&nbsp;</p>
<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, '../images/vin/',6000); // diapo.background=true;
	diapo.start(3000);
OU :
	var diapo = new Diaporama('diapo',0, '',6000);
	diapo.initArray('../images/vin/','10.jpg','toto.jpg','2.jpg');
</script>
*/
