//First page Ads --------------------------------------------------------------------
var fpAds = new Array ();
fpAds.current = 0;

//params :
fpAds.fadeouttime 	= 500;	//0,5 secs
fpAds.fadeintime 	= 1500;
fpAds.timeperad 	= gFirstPageAdsLoop*1000;
fpAds.quality 		= 4;	//1 is best
//fin params



fpAds.launchAdBlend = function ()
{

	if ($("firstPageAds") == null) return ;
	
	 fpAds.list=getElementsByName_iefix("div", "ad");
	 if (fpAds.list == null) return;
	 
	 
	 //set all to hidden / calculate max height / set z-index to 1
	 maxheight = 0;
	 for(i = 0; i < fpAds.list.length; i++)
	 {
	 	var object = fpAds.list[i];
	 	object.style.visibility = "hidden";
	 	object.style.zIndex = 1;
	 	if (object.offsetHeight > maxheight) maxheight = object.offsetHeight;
	 }
	 //set max height to container
	 //($("firstPageAds")).style.height = maxheight+'px';
	 ($("firstPageAds")).style.height = '400px';
	 //alert("'"+maxheight+"px'");
	 fpAds.current = Math.floor( (Math.random())*(fpAds.list.length) );
	 //alert(fpAds.list + "//" + fpAds.list.length + "/" + fpAds.current);
	 fpAds.Next ();
}

fpAds.Next = function ()
{
	//hide current 
	opacity (fpAds.list[fpAds.current].id, 100, 0, fpAds.fadeouttime);
	
	//set it to backgroup
	fpAds.list[fpAds.current].style.zIndex = 1;
	
	//set new to current
	fpAds.current += 1;
	if (fpAds.current > (fpAds.list.length-1)) //fin du tableau, revenir au début
	{
		fpAds.current = 0;
	}
	
	//show new
	opacity (fpAds.list[fpAds.current].id, 0, 100, fpAds.fadeintime);
	//set it to foreground
	fpAds.list[fpAds.current].style.zIndex = 2;
	
	//schedule next call to this func
	setTimeout("fpAds.Next()",fpAds.timeperad);
}

fpAds.Resize = function ()
{
	if ($("firstPageAds") == null) return ;
	
	 fpAds.list=getElementsByName_iefix("div", "ad");
	 if (fpAds.list == null) return;
	 
	 
	 //set all to hidden / calculate max height / set z-index to 1
	 maxheight = 0;
	 for(i = 0; i < fpAds.list.length; i++)
	 {
	 	var object = fpAds.list[i];
	 	object.style.visibility = "hidden";
	 	object.style.zIndex = 1;
	 	if (object.offsetHeight > maxheight) maxheight = object.offsetHeight;
	 }
	 //set max height to container
	 ($("firstPageAds")).style.height = maxheight+'px';
	
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i-=fpAds.quality) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i+=fpAds.quality)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	
	if (opacity <= 0)
	{
		object.visibility = 'hidden';
	}
	else
	{
		object.visibility = 'visible';
	}
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

addLoadEvent (fpAds.launchAdBlend);
addAllLoadedEvent (fpAds.Resize);
//Fin First page Ads --------------------------------------------------------------------