//
// montage2.js
//

var monBlock2	= null;
var monImg2		= null;
var monIdx2		= 0;
var moncontainer22= null;
var monTimeout2	= 3000;

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 ) ) );
}

function montage2( href, src, caption, width, animate )
{
	// this is the case for browsers that don't support filters...
	var cycle2	= Math.floor( Math.random() * href.length );

	// switch off animation if we're not on broadband
	//var m_montage2	= ( typeof(animate) != "undefined" ? animate : hasBroadband() );
	
	//if( m_montage2 == false || src.length <= 1 || !( isIE4 || isW3C ) )
	//{
		//montage2Picker( href, src, caption, cycle2 );
		//return;
	//}
	
	// go build all of the nested DIVs out
	monIdx2		= cycle2;

	document.writeln( "<span id=\"container2\" style=\" width:713px;height:290px;\">" );

	for( i = 0; i < src.length; i++ )
	{
		// set up a placeholder
		document.writeln( "<span id=\"montage2" + i + "\" style=\"display:none\">" );
		
		montage2Picker( href, src, caption, i );

		document.writeln( "</span>" );
	}

	document.writeln( "</span>" );

	// pull the images out
	monBlock2	= new Array( src.length );
	monImg2		= new Array( src.length );

	for( i = 0; i < src.length; i++ )
	{
		monBlock2[i]	= document.getElementById( "montage2" + i ).style;
		monImg2[i]	= document.getElementById( "monImg2" + i );
		
		if( monImg2[i] == null )
		{
			montage2Picker( href, src, caption, i );
			return;
		}
	//	alert( "foo" );
	}

	moncontainer22 = document.getElementById("container2");
	
	montage2Effects();
}

function montage2Effects()
{
	var nextImage2	= (monIdx2 + 1) % monImg2.length;
	
	// run the transition
	if( readIEVer() >= 4.0 )
	{
		moncontainer22.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.0,transition=7)";
	
		moncontainer22.filters(0).apply();
		moncontainer22.filters(1).apply();
		
 		montage2Select( nextImage2 );
		
		moncontainer22.filters(0).play();
		moncontainer22.filters(1).play();
	}
	else
	{
		montage2Select( nextImage2 );
	}

	// asked to be called again a little later
	setTimeout( "montage2Swap()", monTimeout2 );
}

function montage2Select( nextImage2 )
{
	//alert( monImg2[monIdx2].style.visibility );
	monBlock2[monIdx2].display = "none";
	monIdx2 = nextImage2;
	monBlock2[monIdx2].display = "block";
}		

function montage2Swap()
{
	if( monImg2[monIdx2].complete )
	{
		// move the image index along
		montage2Effects();
	}
	else
	{
		// check again 3 seconds later
		setTimeout( "montage2Swap()", 3000 );
	}
}

function montage2Picker( href, src, caption, cycle2 )
{
	if( href[cycle2] != null ) 
	{
		document.writeln( "<A HREF=\"" + href[cycle2] + "\"><IMG SRC=\"" + src[cycle2] + "\" alt=\"" + caption[cycle2]  + "\" BORDER=\"0\" ID=\"monImg2" + cycle2 + "\" width=713 height=290></a>" );
	}
	else
	{
		document.writeln( "<IMG SRC=\"" + src[cycle2] + "\" ID=\"monImg2" + cycle2 + "\" width=713 height=290><br />" );
	}
}

function hasBroadband()
{
	if( readIEVer() < 5.0 )
	{
		return false;
	}
	
	try
	{
		document.body.addBehavior ("#default#clientCaps");
	
		return ( typeof(document.body.connectionType) != "undefined" && document.body.connectionType == "lan" );
	}
	catch( e )
	{
		return false;
	}
}

// -------------------------------------------------------------
// end of montage2.js
// -------------------------------------------------------------
