var DiapoRes;
function Diapo (pName,pSource,pArtisteNo) {
	//var
	this.clickable = true;
	this.name = pName;
	this.source = gid(pSource); // id de la div oł la fichier xml est inclus (div invisible)
	this.siteStart = 0;
	this.siteEnd = 4;
	this.siteMax = 4; // max de realisation afficher par page
	this.oeuvres = Array();
}

Diapo.prototype.createTable = function() {
	this.preloadImg();
};

Diapo.prototype.preloadImg = function () {
	var tempImg = new Image();
	var temp = this.source.getElementsByTagName("item");
	for (var i=0;i<temp.length;i++)	{
		tempImg = new Image();
		tempImg.src = "images/realisations/" + temp[i].getElementsByTagName("mini")[0].firstChild.nodeValue;
		var tmp = new Repro(i,tempImg.src,"images/realisations/" + temp[i].getElementsByTagName("grand")[0].firstChild.nodeValue,temp[i].getElementsByTagName("desc")[0].firstChild.nodeValue);
		this.oeuvres.push(tmp);	
	}
};

Array.prototype.push = function() {
    var n = this.length >>> 0;
    for (var i = 0; i < arguments.length; i++) {
        this[n] = arguments[i];
        n = n + 1 >>> 0;
    }
    this.length = n;
    return n;
};

Diapo.prototype.toHtml = function() {
	var i = this.siteStart
	var j=0;
	var str = "";
	while (((i<this.siteEnd)&&(j<this.siteMax)) && (j<this.oeuvres.length)){
		this.oeuvres[i].setOnClick("onclick='" +this.name + ".centrerImg(this.id)'");
		str += this.oeuvres[i].toMiniHtml();
		if ((this.siteEnd>this.oeuvres.length)&&(i == (this.oeuvres.length-1))){
			i = -1;
		}
	i++;
	j++;   
	}
	if (this.siteMax<this.oeuvres.length) {
		return "<img id='flecheg' class='flecheg' src='images/fleches_haut.gif' onclick='" + this.name + ".backImg()' />" + str + "<img id='fleched' class='fleched' src='images/fleches_bas.gif' onclick='" + this.name + ".nextImg()' />"
	}
	return /*strFleche + */str;
};

Diapo.prototype.backImg = function () {
		this.siteStart--;
		if (this.siteStart<0) {
			this.siteStart = (this.oeuvres.length-1);
		}
		this.siteEnd = this.siteStart + this.siteMax;
		gid("mini_realisation").innerHTML = this.toHtml();
};

Diapo.prototype.nextImg = function () {
		this.siteStart++;
		if (this.siteStart>(this.oeuvres.length-1)){
			this.siteStart=0;
		}
		this.siteEnd = this.siteStart + this.siteMax;
		gid("mini_realisation").innerHTML = this.toHtml();
};

Diapo.prototype.centrerImg = function () {
	if (this.clickable) {
		this.clickable = false;
		Effect.Fade('bigImg', {duration:1});
		var numId = arguments[0].split("_");
		numId = parseInt(numId[1]);
		
		func = function(self,pNum) {
			Effect.Appear('bigImg', {duration:1});
			
		}
		func2 = function(self,pNum) {
			gid("bigImg").src = self.oeuvres[pNum].bigSrc;
			//gid("resDesc").innerHTML = self.oeuvres[pNum].desc;
		}

	setTimeout("func2(DiapoRes,'" + numId +"')",1000);
	setTimeout("func(DiapoRes,'" + numId +"')",2000);
	setTimeout("DiapoRes.setClickable(true)",3000);
	}
};

Diapo.prototype.setClickable = function() {
	this.clickable = arguments[0];
}

function Repro(pId,pSrc,pBigSrc,pDesc) {
	this.id = "repro_" + pId;
	this.src = pSrc;
	this.bigSrc = pBigSrc;
	this.className = "";
	this.onclickevent ="";
	this.desc = pDesc;
}

Repro.prototype.toMiniHtml = function () {
	return "<img " + this.onclickevent + " id='" + this.id + "' src='" + this.src + "' class='miniimg' />";
};

Repro.prototype.setClass = function () {
	this.className = arguments[0];
};

Repro.prototype.setOnClick = function () {
	this.onclickevent = arguments[0];
};

function init() {
	DiapoRes = new Diapo("DiapoRes","xmlRes","0");
	DiapoRes.createTable();
	gid("mini_realisation").innerHTML = DiapoRes.toHtml();
	DiapoRes.centrerImg("repro_0");
	
}

function gid (pcomp) {
	return document.getElementById(pcomp);
}

