var speed = 10;         // vitesse du fondu
//var sleep = 2;          // pause entre chaque image, en secondes

function lance_slideshow(name_div1,name_div2,tab_image,compteur,sleep){	
	eval("trans"+compteur+" = new Array();");
	eval("fading"+compteur+"=''");
	a=0;
	b=1;
	back0 = document.getElementById(name_div1);
	front0 = document.getElementById(name_div2);	
	back0.style.backgroundImage = 'url(' + '\'' + tab_image[a] + '\'' + ')';
	front0.style.backgroundImage = 'url(' + '\'' + tab_image[b] + '\'' + ')';	
	setTimeout(function() { fade_loop(a, b,name_div1,name_div2,tab_image,compteur,sleep); }, sleep * 1000);
}

function fade_in(a, b,name_div1,name_div2,tab_image,compteur,sleep) {
	if (eval("trans"+compteur+"["+b+"]") < 100) {
		eval("trans"+compteur+"["+b+"] = trans"+compteur+"["+b+"]+2");
		front0 = document.getElementById(name_div2);
		if (document.all) { front0.filters.alpha.opacity = eval("trans"+compteur+"["+b+"]"); }
		front0.style.MozOpacity = Math.min(parseFloat(front0.style.MozOpacity) + 0.02, 0.99);
		front0.style.opacity = Math.min(parseFloat(front0.style.opacity) + 0.02, 0.99);

		if (eval("trans"+compteur+"["+b+"]") == 100) {
			eval("clearInterval(fading"+compteur+")");
			c = b + 1; if (!tab_image[c]) { c = 0; }

			nbimages = tab_image.length;
			g=b;
			while(g==b){
				g=Math.floor(nbimages*Math.random());
			}
			setTimeout(function() { fade_loop(b, c,name_div1,name_div2,tab_image,compteur,sleep); }, sleep * 1000);			
		}
	}
}

function fade_loop(a,b,name_div1,name_div2,tab_image,compteur,sleep) {
	if(eval("fading"+compteur)){eval("clearInterval(fading"+compteur+");");}
	back0 = document.getElementById(name_div1);
	front0 = document.getElementById(name_div2);

	back0.style.backgroundImage = 'url(' + '\'' + tab_image[a] + '\'' + ')';
	front0.style.backgroundImage = 'url(' + '\'' + tab_image[b] + '\'' + ')';

	eval("trans"+compteur+"["+a+"]=0");
	eval("trans"+compteur+"["+b+"]=0");

	if (document.all) { front0.filters.alpha.opacity = 0;}
	front0.style.MozOpacity = 0;
	front0.style.opacity = 0;
	gfds = setInterval(function(){fade_in(a,b,name_div1,name_div2,tab_image,compteur,sleep); }, sleep);
	eval("fading"+compteur+"="+gfds);
}
