// on initialise le tableau/liste des images et la variable de position dans le tableau

var liste_images=new Array();
var encours = 0;
var leload = 0;
var laRandom = 0;
var isRandom = false;

/* récupère la liste des images de la page et affiche la première */

function init_image(le_tableau) {
	
	isRandom = false;
	
	document.getElementById("image0").style.display = 'none';
	liste_images = le_tableau;
	document.getElementById("image0").setAttribute("src", "/photo/" + liste_images[encours] + "");
	
	charge_image( "/photo/" + liste_images[encours] + "" );
}

/* affiche une image au hasard dans liste_images */

function random_image() {
	
	isRandom = true;
	
	document.getElementById("image0").style.display = 'none';
	
	liste_images = new Array( "autres/00.jpg", "autres/01.jpg", "autres/02.jpg", "autres/03.jpg", "autres/04.jpg", "autres/05.jpg", "autres/07.jpg", "autres/08.jpg", "autres/09.jpg", "autres/10.jpg", "autres/11.jpg");
	laRandom = Math.floor(Math.random()*liste_images.length);
	
	document.getElementById("image0").setAttribute("src", "/photo/" + liste_images[laRandom] + "");
	
	charge_image( "/photo/" + liste_images[laRandom] + "" );
	//document.getElementById("image0").setAttribute("src", "/photo/" + liste_images[encours] + "");
	//document.getElementById("image0").style.display = 'block';
}

function random_fond() {
	
	isRandom = true;
	
	document.getElementById("image0").style.display = 'none';
	
	liste_images = new Array("fonds/01.jpg", "fonds/02.jpg", "fonds/03.jpg", "fonds/04.jpg", "fonds/05.jpg", "fonds/06.jpg", "fonds/07.jpg");
	laRandom = Math.floor(Math.random()*liste_images.length);
	
	document.getElementById("image0").setAttribute("src", "/photo/" + liste_images[laRandom] + "");
	
	charge_image( "/photo/" + liste_images[laRandom] + "" );
	//document.getElementById("image0").setAttribute("src", "/photo/" + liste_images[encours] + "");
	//document.getElementById("image0").style.display = 'block';
}


/* affiche l'image précédente dans la liste en décrémentant la variable encours. fais une boucle dans le tableau si nécessaire */

function image_precedente() {
	encours--;
	if(encours<0){
	encours = liste_images.length - 1;	
	}
	
	charge_image( "/photo/" + liste_images[encours] + "" );
}


/* affiche l'image suivante dans la liste en incrémentant la variable encours. fais une boucle dans le tableau si nécessaire */

function image_suivante() {
	encours++;
	if(encours>liste_images.length - 1){
	encours = 0;	
	}
	if(encours>10){
	encours = 0;	
	}
	
	charge_image( "/photo/" + liste_images[encours] + "" );
}


/* ramene la photo au premier plan et affiche le menu de navigation image.
S'il n'y a qu'une seule image dans la liste, les boutons "image suivante" et "image précédente" ne s'affichent pas */

function image_devant() {
document.getElementById('image').style.zIndex = 500;
document.getElementById('image_menu').style.display = 'block';

if (liste_images.length < 2){
	document.getElementById('image_prec').style.display = 'none';
	document.getElementById('image_suiv').style.display = 'none';
	}
}

/* renvoie la photo dans le fond et cache le menu navigation image */

function image_derriere() {
document.getElementById('image').style.zIndex = 10;
document.getElementById('image_menu').style.display = 'none';
}


function charge_image(urlimg){
	
document.getElementById('loading').style.display = 'block';

imagen=new Image();
imagen.src= urlimg;
setTimeout('checkload()' , 200);
}

function checkload(){
	
leload++;
if(leload>3){
	leload = 0;	
	}
ajaxpage("/menu/charge" + leload + ".html", "loading");

(imagen.complete)? hideperouter() : setTimeout('checkload()', 200);
}

function hideperouter(){
	document.getElementById('loading').style.display = 'none';
	
	if(isRandom){
		
		document.getElementById("image0").setAttribute("src", "/photo/" + liste_images[laRandom] + "");
		
	}else{
	
	document.getElementById("image0").setAttribute("src", "/photo/" + liste_images[encours] + "");

	};
	
	//Pixastic.revert(document.getElementById("image0"));
	//Pixastic.process(document.getElementById("image0"), "coloradjust", {red:-0.2,green:0.2,blue:-0.1});
	//Pixastic.process(document.getElementById("image0"), "brightness", {brightness:0,contrast:0.1});
	document.getElementById("image0").style.display = 'block';
	
	
}


