function ImageRotator( fromObj, toObj, images, currentIndex, milliseconds, frames, delay )
{	
	currentIndex++;
	
	if( currentIndex >= images.length )
		currentIndex = 0;
	
	// Note: I have to create a new object rather then changing
	// the src, becuase IE dosn't like just chaning the src
	var temp = new Image();
	temp.src = images[currentIndex];
	temp.style.visibility = toObj.style.visibility;
	temp.className = toObj.className;
	toObj.parentNode.appendChild(temp);
	toObj.parentNode.removeChild(toObj);
	toObj = temp;
		
	CrossFade( fromObj, toObj, milliseconds, frames );
	
	var tempFunciton = function() { ImageRotator( toObj, fromObj, images, currentIndex, milliseconds, frames, delay ); };
			
	setTimeout( tempFunciton, delay + milliseconds );
	
}

function CrossFade( fromObj, toObj, milliseconds, frames )
{
	fromObj.style.zIndex = "1"
	toObj.style.zIndex = "2"
	
	SetOpacity( toObj, 0 );
	 
	Fade(toObj, milliseconds, frames, false)
			
}

function Fade( obj, milliseconds, frames, isFadeOut )
{
		ApplyFade( obj, milliseconds / frames , isFadeOut ? 100 : 0, isFadeOut ? 0 : 100, 100 / frames)
}


function ApplyFade( obj, frameRate, currentOpacity, targetOpacity, opacityPerTick )
{	

	//HACK: IE5 crashes under Win98, so just jump to the target opacity
	// It would be better if we could detect the reason for the crash rather then specifing
	// the browser version, but it was something to do with multiple calls to setTimeout
	var version = 10
	if( navigator.appVersion.indexOf("MSIE") != -1 ) {
		var temp = navigator.appVersion.split("MSIE")
		version = parseFloat(temp[1])
	}
	if( version < 6 ) {
		SetOpacity( obj, targetOpacity );
		return;
	}
	
	if ( currentOpacity < targetOpacity )
	{
		currentOpacity = currentOpacity + opacityPerTick
		if ( currentOpacity > targetOpacity )
			currentOpacity = targetOpacity
		SetOpacity( obj, currentOpacity )
	}
	else if ( currentOpacity > targetOpacity )
	{
		currentOpacity = currentOpacity - opacityPerTick
		if ( currentOpacity < targetOpacity )
			currentOpacity = targetOpacity
		SetOpacity( obj, currentOpacity )	
	}
	
	if ( currentOpacity == targetOpacity )
		return;

	var tempFunction = function() { ApplyFade( obj, frameRate, currentOpacity, targetOpacity, opacityPerTick ) };
			
	setTimeout( tempFunction, frameRate );
}

function SetOpacity( obj, opacity )
{
	if( opacity == 0 )
		obj.style.visibility = "hidden";
	else if( obj.style.visibility != "" )
		obj.style.visibility = "";

	// Use 99.999 as opacity to stop Firefox from flickering
	opacity = (opacity == 100) ? 99.999 : opacity;

	// IE / Win
	obj.style.filter = "alpha ( opacity: " + opacity + ")";

	// Safari < 1.2, Konqueror
	obj.style.KHTMLOpacity = opacity / 100;

	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity / 100;

	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity / 100;
}
