// JavaScript Document

// mettre un minimum de 4 images !!!
var coef = 0.03 ; // 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 = 4 ; // nombre d'images a faire bouger
var prefix_image = 'img/photo'; // 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 img1 = null;
var img2 = null ;
var sens = 1;
var tabImg; // tab contenant les images


function prechargerImg()
{
	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;
	}
}


function init()
{
	img1 = document.getElementById("defilement1") ;
	img2 = document.getElementById("defilement2") ;
	prechargerImg();
	change_opacity(0,1);
}


function change_opacity(opacity1, opacity2)
{
	var newOpacity1;
	var newOpacity2;
	
	SetOpacity(img1, opacity1);
	SetOpacity(img2, opacity2);
	
	if (sens)
	{
		newOpacity1 = opacity1 + coef;
		newOpacity2 = opacity2 - coef;
	}
	else
	{
		newOpacity1 = opacity1 - coef;
		newOpacity2 = opacity2 + coef;
	}
	
	// on fait varié le sens d'opacité du bazar
	if (newOpacity2 <= 0)
	{
		img2.src=tabImg[indice++].src;
		sens = 0;
		if (indice == (tabImg.length)) indice=0;
		window.setTimeout("change_opacity(1,0)",temps_pause) ; // attente
		return 0;
	}
	else if (newOpacity1 <= 0)
	{
		img1.src=tabImg[indice++].src;
		sens = 1;
		if (indice == (tabImg.length)) indice=0;
		window.setTimeout("change_opacity(0,1)",temps_pause) ; // attente
		return 0;
	}
	window.setTimeout("change_opacity("+newOpacity1+","+newOpacity2+")",temps) ; // recursion toutes les x millisec
} 


function SetOpacity( Obj, opa_){
  if(document.all && !window.opera){
       var Val = opa_ * 100;
      Obj.style.filter = "alpha(opacity=" + Val + ");"
    }
    else{
      Obj.style.setProperty( "-moz-opacity", opa_, "");
      Obj.style.setProperty( "-khtml-opacity", opa_, "");
      Obj.style.setProperty( "opacity", opa_, "");
    }
}