var diapo;
var diapoElems = new Array();
var diapoI = 0;
var diapoTime = 5000; // 5 secondes

window.onload = function()
{
	initDiaporama($('diaporama'));
}

function initDiaporama(d)
{
	diapo = d;
	var diapoHeight = diapo.clientHeight;
	var diapoWidth  = diapo.clientWidth;

	j = 0;
	for ( i=0; i<diapo.childNodes.length; ++i )
	{
		elem = diapo.childNodes[i];
		
		if ( elem.src )
		{
			if ( j != 0 )
				elem.style.display = 'none';
				
			ratioW = elem.width / diapoWidth;
			ratioH = elem.height / diapoHeight;
			
			if ( ratioW > 1 && ratioH > 1 )
			{
				if ( ratioW > ratioH )
				{
					newH = Math.ceil(elem.height / ratioW);
					elem.style.width = diapoWidth;
					elem.style.height = newH;
					elem.style.top = ((diapoHeight - newH)/2) +'px';
				}
				else
				{
					newW = Math.ceil(elem.width / ratioH);
					elem.style.width = newW;
					elem.style.height = diapoHeight;
					elem.style.left = ((diapoWidth - newW)/2) +'px';
				}
			}
			
			diapoElems[j++] = elem;
		}
	}
	
	setTimeout('slideShow()', diapoTime);
}

function slideShow()
{
	new Effect.Fade(diapoElems[diapoI]);
	
	if ( ++diapoI >= diapoElems.length )
		diapoI = 0;
		
	new Effect.Appear(diapoElems[diapoI]);
	
	setTimeout('slideShow()', diapoTime);
}
