// mettre un minimum de 4 images !!!

var coef = 0.05 ; // avancement de l'opacité
var temps = 50 ; // temps entre chaque changement d'opacité
var temps_pause = 2000 ; // temps d'attente entre 2 changements d'images
var nombre_image = 8 ; // nombre d'images a faire bouger
var prefix_image = 'Logos/Defil'; // chemin + prefix du nom des images
var suffix_image = '.jpg' ; // suffix + '.extension' du nom des images

// pas touche
var indice = 2; // les 2 premiere image sont deja charger dans le HTML, on commence a la 3eme
var isIE = navigator.userAgent.toLowerCase().indexOf('msie')!=-1 ;
var img1 = null;
var img2 = null ;
var sens = 1;
var tabImg;  // tab contenant les images

function InitDefil()
{
	img1 = document.getElementById("defilement1") ;
	img2 = document.getElementById("defilement2") ;

	tabImg = new Array(nombre_image);
	  
  	for (i=0; i<=nombre_image -1; i++){
		tabImg[i]=new Image();
		tabImg[i].src = prefix_image+(i+1)+suffix_image;
  		}
	
	change_opacity();
}

function get_opacity(img)
{
	if (isIE)  // for IE
		{	opacity = parseFloat(img.filters.alpha.opacity);
		}
	else 
		{	opacity = parseFloat(img.style.opacity);
		}
return opacity;
}

function set_opacity(img, opacity)
{
	if (isIE)  // for IE
		{	img.filters.alpha.opacity = opacity;
		}
	else
		{	img.style.opacity = opacity;
		}
}

function change_opacity()
{	
	var opacity1 = 0 ;
	var opacity2 = 0 ;
	var coeff = coef;
	if (isIE) {coeff = 100*coef;}
	
	opacity1 = get_opacity(img1) + sens * coeff;
	opacity2 = get_opacity(img2) - sens * coeff;
	
	set_opacity(img1, opacity1);
	set_opacity(img2, opacity2);

	// on fait varier le sens d'opacité du bazar
	if (opacity2  <= 0)
	{	img2.src=tabImg[indice++].src;
		sens = -1;
		if (indice == (tabImg.length)) indice=0;
		window.setTimeout("change_opacity()",temps_pause) ; // attente
		return 0;
	}
	else if (opacity1 <= 0)
	{	img1.src=tabImg[indice++].src;
		sens = 1;
		if (indice == (tabImg.length)) indice=0;
		window.setTimeout("change_opacity()",temps_pause) ; // attente
		return 0;
	}
	window.setTimeout("change_opacity()",temps) ; // recursion toutes les x millisec
}