//
// PhotoEfx.js
//

var monImg		= null;
var monAlt		= null;
var monLnk		= null;
var monIdx		= 0;

function PhotoEfxEffects()
{
	var container	= document.getElementById("container");
	var html		= "<a href=\"" + monLnk[monIdx] + "\"><img src=\"" + monImg[monIdx].src + "\" alt=\"" + monAlt[monIdx] + "\" border=\"0\"></a>";
	
	// simple case where there's only one thing in the rotation... and no transitions
	if( monImg.length <= 1 )
	{
		container.innerHTML = html;
		return;
	}

	// run the transition
	if( readIEVer() >= 4.0 )
	{
		container.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.0,transition=7)";
		container.filters(0).apply();
		container.filters(1).apply();
		container.innerHTML = html;
		container.filters(0).play();
		container.filters(1).play();
	}
	else
	{
		container.innerHTML = html;
	}

	// asked to be called again in 10 seconds
	setTimeout( "PhotoEfxSwap()", 10000 );
}

function PhotoEfxSwap()
{
	if( monImg[monIdx].complete )
	{
		// move the image index along
		monIdx			= (monIdx + 1) % monImg.length;
		
		PhotoEfxEffects();
	}
	else
	{
		// check again 3 seconds
		setTimeout( "PhotoEfxSwap()", 3000 );
	}
}

function PhotoEfx( href, src, caption, width )
{
	// this is the case for browsers that don't support filters...
	var cycle	= Math.floor( Math.random() * href.length );
	
	if( typeof(document.body) == "undefined" || typeof(document.body.innerHTML) == "undefined" )
	{
		picker( href, src, caption, cycle );
		return;
	}

	if( isIE4 || isW3C )
	{
		monLnk		= href;
		monImg		= new Array( src.length );
		monAlt		= caption;
		
		// get just the first image right now...
		img = new Image( width );
			
		// pick a random image to start from
		monIdx = cycle;
		
		img.src		= src[monIdx];
		img.border	= 0;
		monImg[monIdx]	= img;

		// set up a placeholder
		document.write( "<div id=\"container\" style=\"width:" + width +"px;height:149px\"></div>" );
	
		// switch in the first image
		PhotoEfxEffects();

		// now pre-cache the remaining images
		for( i = 0; i < src.length; i++ )
		{
			if( i != cycle )
			{
				img = new Image( width );
				
				img.src		= src[i];
				img.border	= 0;
				monImg[i]	= img;
			}
		}		

		return;
	}
	
	picker( href, src, caption, cycle );
}

function picker( href, src, caption, cycle )
{
	if( href[cycle] != null ) 
	{
		document.write( "<A HREF=\"" + href[cycle] + "\"><IMG SRC=\"" + src[cycle] + "\" alt=\"" + caption[cycle] + "\" BORDER=\"0\"></a>" );
	}
	else
	{
		document.write( "<IMG SRC=\"" + src[cycle] + "\">" );
	}
}

// -------------------------------------------------------------
// end of PhotoEfx.js
// -------------------------------------------------------------
