var mon2Block	= null;
var mon2Img		= null;
var mon2Idx		= 0;
var mon2Container= null;
var mon2Timeout	= 5000;

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 mon2tagesmall( 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_mon2tagesmall	= ( typeof(animate) != "undefined" ? animate : hasBroadband() );
	
	//if( m_mon2tagesmall == false || src.length <= 1 || !( isIE4 || isW3C ) )
	//{
		//mon2tagesmallPicker( href, src, caption, cycle2 );
		//return;
	//}
	
	// go build all of the nested DIVs out
	mon2Idx		= cycle2;

	document.writeln( "<span id=\"container2\" style=\" width:248px;height:172px;\">" );

	for( i = 0; i < src.length; i++ )
	{
		// set up a placeholder
		document.writeln( "<span id=\"mon2tagesmall" + i + "\" style=\"display:none\">" );
		
		mon2tagesmallPicker( href, src, caption, i );

		document.writeln( "</span>" );
	}

	document.writeln( "</span>" );

	// pull the images out
	mon2Block	= new Array( src.length );
	mon2Img		= new Array( src.length );

	for( i = 0; i < src.length; i++ )
	{
		mon2Block[i]	= document.getElementById( "mon2tagesmall" + i ).style;
		mon2Img[i]	= document.getElementById( "mon2img" + i );
		
		if( mon2Img[i] == null )
		{
			mon2tagesmallPicker( href, src, caption, i );
			return;
		}
	//	alert( "foo" );
	}

	mon2Container = document.getElementById("container2");
	
	mon2tagesmallEffects();
}

function mon2tagesmallEffects()
{
	var nextImage2	= (mon2Idx + 1) % mon2Img.length;
	
	// run the transition
	if( readIEVer() >= 4.0 )
	{
		mon2Container.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.5,transition=12)";
	
		mon2Container.filters(0).apply();
		mon2Container.filters(1).apply();
		
 		mon2tagesmallSelect( nextImage2 );
		
		mon2Container.filters(0).play();
		mon2Container.filters(1).play();
	}
	else
	{
		mon2tagesmallSelect( nextImage2 );
	}

	// asked to be called again a little later
	setTimeout( "mon2tagesmallSwap()", mon2Timeout );
}

function mon2tagesmallSelect( nextImage2 )
{
	//alert( mon2Img[mon2Idx].style.visibility );
	mon2Block[mon2Idx].display = "none";
	mon2Idx = nextImage2;
	mon2Block[mon2Idx].display = "block";
}		

function mon2tagesmallSwap()
{
	if( mon2Img[mon2Idx].complete )
	{
		// move the image index along
		mon2tagesmallEffects();
	}
	else
	{
		// check again 3 seconds later
		setTimeout( "mon2tagesmallSwap()", 6000 );
	}
}

function mon2tagesmallPicker( href, src, caption, cycle2 )
{
	if( href[cycle2] != null ) 
	{
		document.writeln( "<A HREF=\"" + href[cycle2] + "\"><IMG SRC=\"" + src[cycle2] + "\" BORDER=\"0\" ID=\"mon2img" + cycle2 + "\" width=248 height=172></a>" );
	}
	else
	{
		document.writeln( "<IMG SRC=\"" + src[cycle2] + "\" ID=\"mon2img" + cycle2 + "\" width=248 height=172><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;
	}
}