var maxCount = 29;
var versionIllustration1 = "b";
var versionIllustration2 = "b";
var versionIllustration3 = "b";
var versionIllustration4 = "b";
var arrLinks = Array ();
arrLinks[1] = "";
arrLinks[2] = "http://www.affix.org";
arrLinks[3] = "http://www.afim-france.com";
arrLinks[4] = "http://www.amicsepi.fr";
arrLinks[5] = "http://www.artema-france.org";
arrLinks[6] = "http://www.axema.fr";
arrLinks[7] = "http://www.cisma.fr";
arrLinks[8] = "http://www.fabrilabo.com";
arrLinks[9] = "http://www.ffmi.asso.fr";
arrLinks[10] = "http://www.fim-energetique.fr";
arrLinks[11] = "http://www.snas-abrasifs.com";
arrLinks[12] = "http://www.gifo.org";
arrLinks[13] = "http://www.gimef-france.com";
arrLinks[14] = "http://www.profluid.org";
arrLinks[15] = "http://www.sio-france.com";
arrLinks[16] = "http://www.syndicat-mesure.fr";
arrLinks[17] = "http://www.snct.org";
arrLinks[18] = "http://www.sndec.com";
arrLinks[19] = "http://www.snfr-france.com";
arrLinks[20] = "http://www.snitem.fr";
arrLinks[21] = "http://www.symacap.org";
arrLinks[22] = "http://www.symop.com";
arrLinks[23] = "http://www.synamap.fr";
arrLinks[24] = "http://www.syneg.org";
arrLinks[25] = "http://www.ucmtf.fr";
arrLinks[26] = "http://www.uits-france.com";
arrLinks[27] = "http://www.uniclima.fr";
arrLinks[28] = "http://www.uniq.org";
arrLinks[29] = "http://www.unitam.fr";

// prˇparation des arrays de dispatch
shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};
arrIllustration1 = Array ();
arrIllustration2 = Array ();
arrIllustration3 = Array ();
arrIllustration4 = Array ();
for (i = 0 ; i < Math.floor (maxCount / 4) ; i++)
    arrIllustration1[i] = i + 1;
cpt = 0;
for (j = Math.floor (maxCount / 4) ; j < 2 * Math.floor (maxCount / 4) ; j++) {
    arrIllustration2[cpt] = j + 1;
    cpt++;
}
cpt = 0;
for (j = 2 * Math.floor (maxCount / 4) ; j < 3 * Math.floor (maxCount / 4) ; j++) {
    arrIllustration3[cpt] = j + 1;
    cpt++;
}
cpt = 0;
for (j = 3 * Math.floor (maxCount / 4) ; j < maxCount ; j++) {
    arrIllustration4[cpt] = j + 1;
    cpt++;
}
arrIllustration1 = shuffle (arrIllustration1);
arrIllustration2 = shuffle (arrIllustration2);
arrIllustration3 = shuffle (arrIllustration3);
arrIllustration4 = shuffle (arrIllustration4);
/*alert (arrIllustration1);
alert (arrIllustration2);
alert (arrIllustration3);
alert (arrIllustration4);*/

function rotatePictures () {
/*	intRandomNumber = Math.floor (Math.random () * maxCount);
	if (intRandomNumber == 0) intRandomNumber = 1;
	strRandomNumber = String (intRandomNumber);
	if (strRandomNumber.length < 3) {
		intLength = strRandomNumber.length;
//		for (i = 3; i > intLength; i--)
//			strRandomNumber = "0" + strRandomNumber;
	}
*/
	document.getElementById("illustration1a").src = "../medias/img/logos/" + arrIllustration1[0] + ".jpg";
	document.getElementById("illustration2a").src = "../medias/img/logos/" + arrIllustration2[0] + ".jpg";
	document.getElementById("illustration3a").src = "../medias/img/logos/" + arrIllustration3[0] + ".jpg";
	document.getElementById("illustration4a").src = "../medias/img/logos/" + arrIllustration4[0] + ".jpg";
	document.getElementById("illustration1b").onclick = function () { window.open(arrLinks[arrIllustration1[0]]) };
	document.getElementById("illustration2b").onclick = function () { window.open(arrLinks[arrIllustration2[0]]) };
	document.getElementById("illustration3b").onclick = function () { window.open(arrLinks[arrIllustration3[0]]) };
	document.getElementById("illustration4b").onclick = function () { window.open(arrLinks[arrIllustration4[0]]) };
	
/*	//if (arrLinks[arrIllustration1[0]] != "")
	    document.getElementById("divIllustration1a").onclick = function () { window.open(arrLinks[arrIllustration1[0]]) };
	//if (arrLinks[arrIllustration2[0]] != "")
	    document.getElementById("divIllustration2a").onclick = function () { window.open(arrLinks[arrIllustration2[0]]) };
	//if (arrLinks[arrIllustration3[0]] != "")
	    document.getElementById("divIllustration3a").onclick = function () { window.open(arrLinks[arrIllustration3[0]]) };
	//if (arrLinks[arrIllustration4[0]] != "")
	    document.getElementById("divIllustration4a").onclick = function () { window.open(arrLinks[arrIllustration4[0]]) };*/

	window.setTimeout ("changePicture (1)", 5000);
	window.setTimeout ("changePicture (2)", 10000);
	window.setTimeout ("changePicture (3)", 7500);
	window.setTimeout ("changePicture (4)", 2500);
}
var index = Array ();
index[1] = 0;
index[2] = 0;
index[3] = 0;
index[4] = 0;
function changePicture (number) {
	if (index[number] >= Math.floor (maxCount / 4) - 1)
	    index[number] = 0;
	else
	    index[number] += 1;
	    
strDebug = "";
for (a = 0 ; a < Math.floor (maxCount / 4) - 1 ; a++) {
    strDebug += arrIllustration1[a] + ", " + arrIllustration2[a] + ", " + arrIllustration3[a] + ", " + arrIllustration4[a] + "\n";
}
//alert (strDebug);

//alert (number + "::" + index[number]);
	if (number == 1) {
	    versionIllustration = versionIllustration1;
	    randomIndex = arrIllustration1[index[number]];
	} else if (number == 2) {
	    versionIllustration = versionIllustration2;
	    randomIndex = arrIllustration2[index[number]];
	} else if (number == 3) {
	    versionIllustration = versionIllustration3;
	    randomIndex = arrIllustration3[index[number]];
	} else if (number == 4) {
	    versionIllustration = versionIllustration4;
	    randomIndex = arrIllustration4[index[number]];
	}
	
//alert (randomIndex + "::" + arrLinks[randomIndex]);
/*
	intRandomNumber = Math.floor (Math.random () * maxCount);
	if (intRandomNumber == 0) intRandomNumber = 1;
	strRandomNumber = String (intRandomNumber);
	if (strRandomNumber.length < 3) {
		intLength = strRandomNumber.length;
//		for (i = 3; i > intLength; i--)
//			strRandomNumber = "0" + strRandomNumber;
	}
*/	
	document.getElementById("illustration" + number + versionIllustration).src = "../medias/img/logos/" + randomIndex + ".jpg";
	//document.getElementById("illustration" + number + versionIllustration).onclick = "window.open('" + arrLinks[randomIndex] + "')";
	document.getElementById("illustration" + number + versionIllustration).onclick = new Function ("implementLink('" + arrLinks[randomIndex] + "')");
//	document.getElementById("illustration" + number + versionIllustration).onclick = function () { alert (this.id + " === " + number + "-" + versionIllustration + " - randomIndex : " + randomIndex + ", link : " + arrLinks[randomIndex]) };
	if (versionIllustration == "b"){
		tDiv = "divIllustration" + number + "a";
		vDiv = "divIllustration" + number + "b";
		if (number == 1)
			versionIllustration1 = "a";
		else if (number == 2)
			versionIllustration2 = "a";
		else if (number == 3)
			versionIllustration3 = "a";
		else if (number == 4)
			versionIllustration4 = "a";
	} else {
		tDiv = "divIllustration" + number + "b";
		vDiv = "divIllustration" + number + "a";
		if (number == 1)
			versionIllustration1 = "b";
		else if (number == 2)
			versionIllustration2 = "b";
		else if (number == 3)
			versionIllustration3 = "b";
		else if (number == 4)
			versionIllustration4 = "b";
	}
	fx1a = new Fx.Tween(tDiv, {duration: 1000});
	fx1a.start ('opacity', '1', '0');
	//if (arrLinks[randomIndex] != "")
	//    document.getElementById(vDiv).onclick = function () { window.open(arrLinks[randomIndex]) };
	fx1b = new Fx.Tween(vDiv, {duration: 1000});
	fx1b.start ('opacity', '0', '1');

	window.setTimeout ("changePicture (" + number + ")", 10000);
}
/*window.addEvent('domready', function() {
	rotatePictures();
});*/

function implementLink (link) {
    window.open (link);
}
window.onload = rotatePictures;

