window.RotatorInstanceNumber = 0;
window.RotatorInstance = new Array();

function SetOpacity(fObject, fOpacity)
{
	fObject.style.filter = 'alpha(opacity = ' + (fOpacity * 100) + ')';
	fObject.styleMsFilter = '"alpha(opacity = ' + (fOpacity * 100) + ')"'; 
	fObject.style.opacity = fOpacity;
}

function ObjectRotator(fObject, fAdd, fTime, fDelay, fNumbers, fNames, fLinks, fDirectory)
{
	fObject.RotatorID = window.RotatorInstanceNumber ++;
	fObject.RotatorOpacity = 1;
	fObject.RotatorAdd = fAdd;
	fObject.RotatorTime = fTime * 1000;
	fObject.RotatorDelay = fDelay * 1000;
	fObject.RotatorIndex = 0;
	fObject.NumberList = fNumbers;
	fObject.NameList = fNames;
	fObject.LinkList = fLinks;
	fObject.Directory = fDirectory;

	SetOpacity(fObject, 1);

	window.RotatorInstance[fObject.RotatorID] = fObject;
	
	fObject.parentNode.style.backgroundImage = 'url(\'' + fDirectory + '/' + ((fNumbers.length > 1) ? fNumbers[1] : fNumbers[0]) + '.gif\')';
	
	setTimeout('RotatorChange(' + fObject.RotatorID + ');', fDelay * 1000);
}

function RotatorOpacityChange(fInstanceID)
{
	var WorkObject = window.RotatorInstance[fInstanceID];

	WorkObject.RotatorOpacity = Math.max(WorkObject.RotatorOpacity - WorkObject.RotatorAdd, 0);
	
	SetOpacity(WorkObject, WorkObject.RotatorOpacity);

	if (WorkObject.RotatorOpacity == 0)
	{
		clearInterval(WorkObject.RotatorInterval);

		if (++ WorkObject.RotatorIndex >= WorkObject.NumberList.length)
		{
			WorkObject.RotatorIndex = 0;
		}

		LinkObject = WorkObject.parentNode;
		
		CurrentName = ((WorkObject.NameList.constructor != Array) ? WorkObject.NameList : WorkObject.NameList[WorkObject.RotatorIndex]);
		CurrentLink = ((WorkObject.LinkList.constructor != Array) ? WorkObject.LinkList : WorkObject.LinkList[WorkObject.RotatorIndex]);
		
		WorkObject.src = WorkObject.Directory + '/' + WorkObject.NumberList[WorkObject.RotatorIndex] + '.gif';
		WorkObject.alt = CurrentName;
		
		if (CurrentLink.length > 0)
		{
			LinkObject.href = CurrentLink;
			LinkObject.style.cursor = 'pointer';
		}
		else
		{
			LinkObject.removeAttribute('href');
			LinkObject.style.cursor = 'default';
		}
		
		SetOpacity(WorkObject, 1);
		WorkObject.RotatorOpacity = 1;
		
		LinkObject.style.backgroundImage = 'url("' + WorkObject.Directory + '/' + ((WorkObject.RotatorIndex + 1 >= WorkObject.NumberList.length) ? WorkObject.NumberList[0] : WorkObject.NumberList[WorkObject.RotatorIndex + 1]) + '.gif")';
		
		setTimeout('RotatorChange(' + fInstanceID + ');', WorkObject.RotatorDelay);
	}
}

function RotatorChange(fInstanceID)
{
	RotatorObject = window.RotatorInstance[fInstanceID];

	RotatorObject.RotatorInterval = setInterval('RotatorOpacityChange(' + RotatorObject.RotatorID + ', true);', RotatorObject.RotatorTime);
}