var FND_DELAI = 20;
var FND_SPEED = 0.03;
var FND_MIN = 0;
var FND_MAX = 1.0;
var FND_DUREE_PICT = 2000;

function FND_SetOnImageLoaded (fn)
{
	document._onImageLoaded = fn;
}

function FND_ImgLoaded ()
{
	this.canuse = true;
	this.width = 400;
	this.height = 267;
	
	if (  document._onImageLoaded
		&& this._callLoaded
		)
	{
		document._onImageLoaded ();
		document._onImageLoaded = null;
	}
}

function FND_GetImgCour ()
{
	return document._Imgs [document._IndexFonduCour];
}

function FND_InitFondu (idDiv)
{
	document.divConteneur = xGetElementById (idDiv);	
	
	if (document.divConteneur)
	{
		if (!document._Imgs)
			document._Imgs = new Array ();
			
		for (var i = 1; i < arguments.length; ++i) 
		{
			var urlImgTransition = arguments [i];
			var img = new Image ();
			var style = img.style;
			if (style)
			{
				if (i == 1)
					img._callLoaded = true;
				img.canuse = false;
				img.onload = FND_ImgLoaded;
				img.src = urlImgTransition;
				xDisplay (img, 'none')
				document._Imgs.push (img);
				document.divConteneur.appendChild (img);
			}
		}

		if (document._Imgs.length > 0)
			FND_StartFondu ();
	}
}

function FND_StartFondu ()
{
	FND_FindNextFondu();
	FND_ApparaitreImg ();
}

function FND_FindNextFondu ()
{
	if (!document._IndexFonduCour)
		document._IndexFonduCour = 0;
	
	xDisplay (FND_GetImgCour (), 'none')
	
	var deb = document._IndexFonduCour;
	var notfound = false;
	do
	{
		if (++document._IndexFonduCour >= document._Imgs.length)
			document._IndexFonduCour = 0;
		
		if (deb == document._IndexFonduCour)
		{
			notfound = true;
			break;
		}
	}
	while (!FND_GetImgCour.canuse)
	
	if (notfound)
	{
		if (++document._IndexFonduCour >= document._Imgs.length)
			document._IndexFonduCour = 0;
	}
	
	FND_AdjustFondu (0);
	xDisplay (FND_GetImgCour (), 'block')
}

function FND_DisparaitreImg ()
{
	if (!document._tauxFondu)
		document._tauxFondu = FND_MAX;
		
	document._tauxFondu -= FND_SPEED;
		
	FND_AdjustFondu (document._tauxFondu);
	
	if (document._tauxFondu > FND_MIN)
	{
		window.setTimeout ('FND_DisparaitreImg();', FND_DELAI);
	}
	else
	{
		FND_FindNextFondu();
		window.setTimeout ('FND_ApparaitreImg();', FND_DELAI);
	}
}

function FND_ApparaitreImg ()
{
	if (!document._tauxFondu)
		document._tauxFondu = FND_MIN;
	
	document._tauxFondu += FND_SPEED;
	
	FND_AdjustFondu (document._tauxFondu);
	
	if (document._tauxFondu >= FND_MAX)
		window.setTimeout ('FND_DisparaitreImg();', FND_DUREE_PICT);
	else
		window.setTimeout ('FND_ApparaitreImg();', FND_DELAI);
}

function FND_AdjustFondu (taux)
{
	xOpacity (FND_GetImgCour (), taux);
}
