/*
	Image Cross Fade Redux
	Version 1.0
	Last revision: 02.15.2006
	steve@slayeroffice.com

	Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
*/

window.addEventListener?window.addEventListener('load',so_initP,false):window.attachEvent('onload',so_initP);

var dP=document, imgsP = new Array(), zIntervalP = null, currentP=0, pauseP=false;

function so_initP()
{
	if(!dP.getElementById || !dP.createElement)return;

	css = dP.createElement('link');
	css.setAttribute('href','css/slideshowPartners2.css');
	css.setAttribute('rel','stylesheet');
	css.setAttribute('type','text/css');
	dP.getElementsByTagName('head')[0].appendChild(css);

	imgsP = dP.getElementById('partners').getElementsByTagName('img');
	for(i=1;i<imgsP.length;i++) imgsP[i].xOpacity = 0;
	imgsP[0].style.display = 'block';
	imgsP[0].xOpacity = .99;

	setTimeout(so_xfadeP,7000); //primo fade
}

function so_xfadeP()
{
	cOpacity = imgsP[currentP].xOpacity;
	nIndex = imgsP[currentP+1]?currentP+1:0;
	nOpacity = imgsP[nIndex].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	imgsP[nIndex].style.display = 'block';
	imgsP[currentP].xOpacity = cOpacity;
	imgsP[nIndex].xOpacity = nOpacity;

	setOpacity(imgsP[currentP]);
	setOpacity(imgsP[nIndex]);

	if(cOpacity<=0)
	{
		imgsP[currentP].style.display = 'none';
		currentP = nIndex;
		setTimeout(so_xfadeP,5000); //altri fade
	}
	else
	{
		setTimeout(so_xfadeP,50);
	}

	function setOpacity(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}
