// Inspirer de : http://www.cybwarrior.com/download/zip/javascript/diaporama/
// Modifier par Antoine Bobin

var Diaporamas = new Array();

function Diaporama(interval)
{
	this.Index = Diaporamas.length;
	this.Images = new Array();
	this.ImgIndex = 0;
	this.ID = null;
	this.interval = interval;
	this.Add = function(id, legende) {
		var Index = this.Images.length;
		var src = "images/miniatures/" + id;
		this.Images[Index] = new Array();
		this.Images[Index]["image"] = new Image();
		this.Images[Index]["image"].src = src;
		this.Images[Index]["rel"] = src;
		this.Images[Index]["legende"] = legende;
		this.Images[Index]["id"] = id;

        /*
        this.Images[Index] = new Image();
		this.Images[Index].src = src;
		this.Images[Index].name = src;
		*/
	}
	this.Show = function(Index) {
		if(Index < 0)Index = this.Images.length - 1;
		if(Index > this.Images.length - 1)Index = 0;
		document.images["disc" + this.Index].src = this.Images[Index]["image"].src;
		this.ImgIndex = Index;
        if (document.getElementById) {
            document.getElementById("diaporama_lien").href = 'fichier-affichage.php?id=' + this.Images[Index]["id"];
            document.getElementById("diaporama_legende").innerHTML = this.Images[Index]["legende"];
        }
	}
	this.First = function() {
		this.Show(0);
	}
	this.Last = function() {
		this.Show(this.Images.length - 1);
	}
	this.Previous = function(){
		if(this.ImgIndex > 0)this.Show(this.ImgIndex - 1);
	}
	this.Next = function() {
		if(this.ImgIndex < this.Images.length - 1)this.Show(this.ImgIndex + 1);
	}
	this.Play = function() {
		this.ID = setInterval("Diaporamas[" + this.Index + "].Show(Diaporamas[" + this.Index + "].ImgIndex + 1);", this.interval);
	}
	this.Stop = function() {
		clearInterval(this.ID);
		this.ID = null;
	}
	this.Click = function(Index) {
		this.Stop();
		this.Show(Index);
	}
	this.Build = function() {
        document.write('<table cellspacing="0" cellpadding="0" style="width: 179px; height: 179px; border: solid 1px #000; position: relative; left: 11px;"><tr><td align="center" valign="middle">');
		document.write('<a id="diaporama_lien" href="fichier-affichage.php?id='+ this.Images[0]["id"] +'" onmouseover="Diaporamas[' + this.Index + '].Stop();" onmouseout="Diaporamas[' + this.Index + '].Play();" onclick="window.open(this.href); return false;"><img src="'+ this.Images[0]["image"].src +'" name="disc' + this.Index +'"'+ ' style="display: block;" /></a>');
        document.write('</td></tr></table>');
		document.write('<div id="diaporama_legende" style="width:177px; padding-top: 5px; text-align: right;">'+ this.Images[0]["legende"] +'</div>');

        if (this.Images.length > 1) {
            this.Play();
        }
	}

	Diaporamas[this.Index] = this;
}