var octet = new Array(); var fondu = new Array("#800000","#860000","#960000","#A60000","#B60000","#C60000","#D60000"); var maxcol = Math.floor(screen.width/100);
var wagon = new Array(); var tailwag = 600; var wagonvu = 0; var coulisseur; var identifiant;
function init_fontaine(){for (var i=0;i<maxcol;i++){var ajoutnode = document.createElement('span'); var nodecontenu = document.createTextNode(i); document.body.insertBefore(ajoutnode, document.getElementById('conteneur'));
		var nodespan  = document.getElementById('conteneur').previousSibling; nodespan.appendChild(nodecontenu); var ajoutattr = document.createAttribute('class');
		ajoutattr.value = "octet"; nodespan.setAttributeNode(ajoutattr); ajoutattr = document.createAttribute('id'); ajoutattr.value = "octet_"+i; nodespan.setAttributeNode(ajoutattr); nodespan.style.left=i*100+"px"; creer_octet(i);}descendre();}
function creer_octet(choix) {var cible = document.getElementById('octet_'+choix); var contenu = new String;	for (var i=0;i<8;i++){var aleabit = Math.round(Math.random());contenu+=aleabit;}
	var vity = Math.round(Math.random()*6)+2;	var posy = -(Math.round(Math.random()*60)+20); var maxy = (document.documentElement.clientHeight-200)+ Math.round(Math.random()*100);
	octet[choix]=new sauver_octet(posy,vity,maxy); cible.style.top=posy+"px";	cible.style.color=fondu[octet[choix].couleur]; cible.firstChild.nodeValue=contenu;}
function sauver_octet(posy,vity,maxy) {this.position = posy;	this.vitesse = vity;	this.maximum = maxy;	this.couleur = 0;}
function descendre() {for (var i=0;i<maxcol;i++){octet[i].position += octet[i].vitesse;	var cible=document.getElementById('octet_'+i); if (octet[i].position>0){cible.style.top = octet[i].position+"px";	if (octet[i].position>octet[i].maximum){
	if (octet[i].couleur<fondu.length-1){octet[i].couleur++; cible.style.color = fondu[octet[i].couleur];}else{creer_octet(i);}}}}window.setTimeout("descendre();", 250);}
function init_glisser(){var pointx = -tailwag; coulisseur = document.getElementById('coulisseur'); var tous_div = coulisseur.getElementsByTagName('div');
	for (var i=0;i<tous_div.length;i++){if (tous_div[i].className=='wagon'){pointx+=tailwag;	wagon[i] = new sauver_wagons(tous_div[i].getAttribute('id'), pointx);}}	var taillex = (wagon.length)*tailwag;	coulisseur.style.width = taillex+"px";
	document.getElementById('coulgauche').onclick = function(){glisser_gauche();return false;};	document.getElementById('couldroite').onclick = function(){glisser_droite();return false;};}
function sauver_wagons(nomwag, pointx){this.nom = nomwag;	this.posx = pointx;}
function glisser_droite(){if (wagonvu==wagon.length-1){return;}	var depax = coulisseur.offsetLeft;	var arrix = -wagon[wagonvu+1].posx;
	if(depax>arrix){coulisseur.style.left=depax-10+"px"; identifiant = window.setTimeout("glisser_droite();",5);}else{window.clearTimeout(identifiant); wagonvu++;}}
function glisser_gauche(){if (wagonvu==0){return;} var depax = coulisseur.offsetLeft; var arrix = -wagon[wagonvu-1].posx;
	if(depax<arrix){coulisseur.style.left=depax+10+"px";	identifiant = window.setTimeout("glisser_gauche();",5);}else{	window.clearTimeout(identifiant);	wagonvu--;}}
window.onload = function() { init_glisser(); init_fontaine(); };