/* Déjà défini :
   var StripSelect (array)
   var numpage (int)
*/

// placement auto dans body onload
if (window.addEventListener){
	window.addEventListener("DOMContentLoaded", initGsW, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", function(){ initGsW(); } );
}

var scrollvotediv, scrollvotevar, scrollvotespeed;
var runningImg, runningGifs = ['donkey-kong', 'kitty', 'link-pot', 'aladdin-genie', 'ghouls-naked', 'mario-yoshi', 'pikachu', 'link-poule', 'lucky-luke', 'eggman'];
var runningImgWidth = 2000;

function initGsW() {
	////// truc de merde sur les iframes pour IE
	ifrs = document.getElementsByTagName('iframe');
	m=ifrs.length;
	for(i=0;i<m;i++) ifrs[i].setAttribute('ALLOWTRANSPARENCY', 'true');


	////// disparition du bouton valider
	document.getElementById('fornoscript').style.display = 'none';
	document.getElementById('fornoscript2').style.display = 'none';


	////// ecriture de tous les éléments JS
	Sel = document.getElementById('pagesel');
	// 0) réécriture de chaque élément
	for (i in StripSelect) StripSelect[i] = StripSelect[i].split('|');
	// 1) virer le select actuel et l'ajouter au StripSelect
	while(Sel.options.length > 0) {
		date_et_titre = Sel.options[0].text.split(' (');
		StripSelect[ Sel.options[0].value ] = new Array(
			Sel.options[0].style.background,
			date_et_titre[1].replace(')',''),
			date_et_titre[0].replace(/^\d+ - /,'')
			);
		Sel.options[0] = null;
	}
	// 2) remplir le select
	j=0;
	for (i in StripSelect) {
		a = new Option(i+' - '+StripSelect[i][2]+' ('+StripSelect[i][1]+')', i);
		a.style.background = StripSelect[i][0];
		Sel.options[j++] = a;
	}
	// 3) selection
	Sel.selectedIndex = numpage-1; // l'index c'est la page - 1


	////// balade des rings
	scrollvotediv = document.getElementById('scrollvote');
	scrollvotevar = 0;
	scrollvotespeed = 4;
	window.setInterval("scrollvote()", 100);


	////// running runningGifs
	runningImg = document.getElementById('runningags').getElementsByTagName('img')[0];
	runningImg.style.left = '-100px';
	runningImgWidth = screen.width - 937;
	setTimeout('runningGo(0)', 2);
}

function runningGo(i) {
	pos = parseInt (runningImg.style.left.replace('px', ''), 10);
	if (pos>runningImgWidth) {
		// ici on court dnas le vide, le gif est caché il importe plus
		// ce if est fait dans le but de diminuer les ressources demandées par JS qui déconnent
		pos += 3;
	}
	else if (pos>2000) {
		i++;
		if (i >= runningGifs.length) i=0;
		runningImg.style.left = '-100px';
		runningImg.src = runningImg.src.replace(/\/[a-z-]+.gif$/, '/'+runningGifs[i]+'.gif');
	}
	else {
		pos += 3;
		runningImg.style.left = pos+'px';
	}
	setTimeout('runningGo('+i+')', 40);
}

function scrollvote() {
	scrollvotevar -= scrollvotespeed;
	if (scrollvotevar<-470) scrollvotevar = 120;
	scrollvotediv.style.left = scrollvotevar+"px";
}

