var imgsets = new Array(), imgs = new Array(), current = new Array(), nIndex = new Array(), T1, nRotate;

function InitRotateFader()
{
	var d=document;
	if(!d.getElementById || !d.createElement)return;

	//add array items here manually
	imgsets[0] = d.getElementById('rotator').getElementsByTagName('img');

	for(iset=0; iset<imgsets.length; iset++) {
		for(i=1;i<imgsets[iset].length;i++) imgsets[iset][i].xOpacity = 0;
		imgsets[iset][0].style.display = 'block';
		imgsets[iset][0].xOpacity = .99;
		current[iset]=0;
	}

	nRotate = 1;
	T1 = setTimeout(ImageFade,3000);
}

function ImageFade()
{
	if (nRotate==1) {
		cOpacity = imgsets[0][current[0]].xOpacity;
		for(iset=0; iset<imgsets.length; iset++) {
			nIndex[iset] = imgsets[iset][current[iset]+1]?current[iset]+1:0;
		}
		nOpacity = imgsets[0][nIndex[0]].xOpacity;
	
		cOpacity-=.05;
		nOpacity+=.05;
	
		for(iset=0; iset<imgsets.length; iset++) {
			imgsets[iset][nIndex[iset]].style.display = 'block';
			imgsets[iset][current[iset]].xOpacity = cOpacity;
			imgsets[iset][nIndex[iset]].xOpacity = nOpacity;
	
			setOpacity(imgsets[iset][current[iset]]);
			setOpacity(imgsets[iset][nIndex[iset]]);
		}
	
		if(cOpacity<=0)
		{
			for(iset=0; iset<imgsets.length; iset++) {
				imgsets[iset][current[iset]].style.display = 'none';
				current[iset] = nIndex[iset];
			}
			T1 = setTimeout(ImageFade,3000);
		}
		else
		{
			T1 = setTimeout(ImageFade,50);
		}
	}
	else {
		T1 = setTimeout(ImageFade,3000);
	}
}

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) + ')';
}

function DisplayStoppedImage()
{
	cOpacity = imgsets[0][current[0]].xOpacity;
	for(iset=0; iset<imgsets.length; iset++) {
		nIndex[iset] = imgsets[iset][current[iset]+1]?current[iset]+1:0;
	}
	nOpacity = imgsets[0][nIndex[0]].xOpacity;

	//show the one that's most clear
	if (cOpacity < 0.5) {
		cOpacity=0;
		nOpacity=.99;
	}
	else {
		cOpacity=.99;
		nOpacity=0;
	}
	
	for(iset=0; iset<imgsets.length; iset++) {
		imgsets[iset][current[iset]].xOpacity = cOpacity;
		imgsets[iset][nIndex[iset]].xOpacity = nOpacity;

		setOpacity(imgsets[iset][current[iset]]);
		setOpacity(imgsets[iset][nIndex[iset]]);
		
		if (nOpacity == 0) {
			imgsets[iset][nIndex[iset]].style.display = 'none';
		}
		else {
			imgsets[iset][current[iset]].style.display = 'none';
		}
	}
}


function StopRotation()
{
	nRotate = 0;
	try
	{
		DisplayStoppedImage();
	}
	catch(err) {
	}
}

function StartRotation()
{
	nRotate = 1;
}