// 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 = 5 ; // nombre d'images a faire bouger
var prefix_image0 = 'gfx/image0'; // chemin + prefix du nom des images
var prefix_image1 = 'gfx/image'; // 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
var star;
var starW,starH,starS,starC=0;

function initAccueil()
{
	star = new Image()
	star.src = 'images/accueil01.jpg';
	star.style.visibility = 'hidden';
	
	starW = star.width;
	starH = star.height;
	starS = 0.05;
	
	star.width = 0;
	star.height = 0;
	star.style.visibility = 'visible';
	
	document.getElementById('accueil-01').appendChild(star);

	zoomStar();
}

function zoomStar()
{
	starC++;
	if (starC*starS<=1)
	{
		star.width = (starC*starS)*starW;
		star.height = (starC*starS)*starH;
		window.setTimeout("zoomStar()", 10) ;
	}
	if (starC*starS==1)
	{
		var noeud=document.getElementById('accueil').firstChild;

		document.getElementById('accueil-01').style.backgroundImage = 'url(images/accueil01.jpg)';
		document.getElementById('accueil-01').style.backgroundRepeat = 'no-repeat';
		document.getElementById('accueil-01').removeChild(noeud);
	}
}

function prechargerImg(nb_img){
  tabImg = new Array(nb_img);
  for (i=0; i<=nb_img -1; i++){
	tabImg[i]=new Image();
	if (i<9)
		tabImg[i].src = prefix_image0+(i+1)+suffix_image;
	else
		tabImg[i].src = prefix_image1+(i+1)+suffix_image;
  }
}

function init(page, path, nb_img)
{
/*	if (page=='accueil')	initAccueil();*/

	if (page!='galeries' && page!='illus' && page!='univers' && page!='univers-xx' && page!='univers-yy' && page!='agenda' && page!='event')
	{
		nombre_image = nb_img;
		prefix_image0 = path+'/image0';
		prefix_image1 = path+'/image';
		
		img1 = document.getElementById("defilement1") ;
		img2 = document.getElementById("defilement2") ;
	
		prechargerImg(nb_img);
		change_opacity();
	}
}

function change_opacity()
{	
	var opacity1 = 0 ;
	var opacity2 = 0 ;
	if (isIE)  // for IE
	{	opacity1 = parseFloat(img1.filters.alpha.opacity);
		opacity2 = parseFloat(img2.filters.alpha.opacity);
	}
	else       // for mozilla
	{	opacity1 = parseFloat(img1.style.opacity);
		opacity2 = parseFloat(img2.style.opacity);
	}

	if (sens)
	{	if (isIE)  // for IE
		{	img1.filters.alpha.opacity = opacity1 + coef * 100;
			img2.filters.alpha.opacity = opacity2 - coef * 100;
		}
		else // for Mozilla
		{	img1.style.opacity = opacity1 + coef;
			img2.style.opacity = opacity2 - coef;
		}
	}
	else
	{
		if (isIE)  // for IE
		{	img1.filters.alpha.opacity = opacity1 - coef * 100;
			img2.filters.alpha.opacity = opacity2 + coef * 100;
		}
		else // for Mozilla
		{	img1.style.opacity = opacity1 - coef;
			img2.style.opacity = opacity2 + coef;
		}
	}

	if (isIE)  // for IE
	{	opacity1 = parseFloat(img1.filters.alpha.opacity);
		opacity2 = parseFloat(img2.filters.alpha.opacity);
	}
	else       // for mozilla
	{	opacity1 = parseFloat(img1.style.opacity);
		opacity2 = parseFloat(img2.style.opacity);
	}

	// on fait variÈ le sens d'opacitÈ du bazar
	if (opacity2  <= 0)
	{	img2.src=tabImg[indice++].src;
		sens = 0;
		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.status = "opa1 : " + opacity1 + "  opa2 : " + opacity2 + "   indice : "+indice;
	window.setTimeout("change_opacity()",temps) ; // recursion toutes les 30 millisec
}
