//
// Stage.js
//

var SBlock	= null;
var SImg	= null;
var SIdx	= 0;
var SContainer= null;
var STimeout	= 7000;

function Stage( href, src, caption, width, animate )
{

	if( src.length <= 1 || !( isIE4 ) )
	{
		StagePicker( href, src, caption, cycle );
		return;
	}
	
	// go build all of the nested DIVs out
	

	document.writeln( "<div id=\"container\" style=\"width:" + width +"px;height:125px\">" );

	for( i = 0; i < src.length; i++ )
	{
		// set up a placeholder
		document.writeln( "\t<div id=\"Stage" + i + "\" style=\"display:none\">" );
		
		StagePicker( href, src, caption, i );

		document.writeln( "\t</div>" );
	}

	// remove document.writeln( "</div>" );

	// pull the images out
	SBlock	= new Array( src.length );
	SImg		= new Array( src.length );

	for( i = 0; i < src.length; i++ )
	{
		SBlock[i]	= document.getElementById( "Stage" + i ).style;
		SImg[i]	= document.getElementById( "Simg" + i );
		
		if( SImg[i] == null )
		{
			StagePicker( href, src, caption, i );
			return;
		}
	//	alert( "foo" );
	}

	SContainer = document.getElementById("container");
	
	StageEffects();
}

// fn-1

function StageEffects()
{
	var nextImage	= (SIdx + 1) % SImg.length;
	
	// run the transition
	if( readIEVer() >= 4.0 )
{

		SContainer.style.filter = "blendTrans(duration=3.0) revealTrans(duration=3.0,transition=17)";
		SContainer.filters(0).apply();
		SContainer.filters(1).apply();
		
 		StageSelect( nextImage );
		
		SContainer.filters(0).play();
		SContainer.filters(1).play();
	
}
	else
	{
		StageSelect( nextImage );
	}

	// asked to be called again a little later
	setTimeout( "StageSwap()", STimeout );
}

// fn-2

function StageSelect( nextImage )
{
	//alert( SImg[SIdx].style.visibility );
	SBlock[SIdx].display = "none";
	SIdx = nextImage;
	SBlock[SIdx].display = "block";
}		

// fn-3

function StageSwap()
{
	if( SImg[SIdx].complete )
	{
		// move the image index along
		StageEffects();
	}
	else
	{
		// check again 3 seconds later
		setTimeout( "StageSwap()", 3000 );
	}
}

// fn-4

function StagePicker( href, src, caption, cycle )
{
	if( href[cycle] != null ) 
	{
	document.writeln( "\t\t<A HREF=\"" + href[cycle] + "\"><IMG SRC=\"" + src[cycle] + "\" alt=\"" + caption[cycle] + "\" BORDER=\"0\" ID=\"Simg" + cycle + "\"></a>" );
	}
	else
	{
		document.writeln( "\t\t<IMG SRC=\"" + src[cycle] + "\" ID=\"Simg" + cycle + "\">" );
	}
}

// -------------------------------------------------------------
// end of Stage.js
// -------------------------------------------------------------
// joined from here

var iihris 		= false;
var isIE4 		= false;


function autoconfig()
{
    {
        iihris		= (document.body && document.body.style) ? true : false;
        isIE4		= (iihris && document.all && readIEVer() >= 4.0) ? true : false;
       
    }
 
}
function readIEVer()
{
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "MSIE" );
	if( offset < 0 )
	{
		return 0;
	}
	return parseFloat( agent.substring( offset + 5, agent.indexOf( ";", offset ) ) );
}



