function detectBrowser()
{
if( document && document.images )
{
isCSS = (document.body && document.body.style) ? true : false;
isW3C = (isCSS && document.getElementById) ? true : false;
isIE4 = (isCSS && document.all && checkIEVer() >= 4.0) ? true : false;
isNN4 = (document.layers) ? true : false;
isGecko = (isCSS && navigator && navigator.product && navigator.product == "Gecko");
isOpera = (isCSS && navigator.userAgent.indexOf( "Opera") != -1 );
isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
isIE6 = ( isIE6CSS && checkIEVer() >= 6.0 );
isDHTML = isCSS && ( isIE4 || isGecko || isOpera );
if( suppressMenus )
{
isDHTML = false;
}
else if( isOpera && checkOperaVer() < 7 )
{
isDHTML = false;
}
else if( isGecko && navigator.productSub <= 20011022 )
{
isDHTML = false;
}
else if( isGecko && navigator.productSub == 20030107 )
{
var x = navigator.userAgent.indexOf( "AppleWebKit" );
if( x > -1 )
{
isDHTML = ( navigator.userAgent.substring( x + 12, x + 15 ) ) > 300;
}
else
{
isDHTML = false;
}
}
}
}

var isCSS = false;
var isW3C = false;
var isIE4 = false;
var isNN4 = false;
var isIE6 = false;
var isGecko = false;
var isOpera = false;
var isDHTML = false;
var suppressMenus = false;
var legacyMode = false;
var timerID = null;
var subtimerID = null;
var m_anchorClicked = false;

function checkIEVer()
	{
	var agent = navigator.userAgent;
	var offset = agent.indexOf( "MSIE" );
	if( offset < 0 )
	{
	return 0;
	}
	return parseFloat( agent.substring( offset + 5, agent.indexOf( ";", offset ) ) );
}
function checkOperaVer()
	{
	var agent = navigator.userAgent;
	var offset = agent.indexOf( "Opera" );
	if( offset < 0 )
	{
	return 0;
	}
	return parseFloat( agent.substring( offset + 6 ) );
}


// animation setup
var aniBlock	= null;
var aniImg		= null;
var aniIdx		= 0;
var aniContainer= null;
var aniTimeout	= 7000;
var aniEffect	= 2;
var aniHref;
var aniSrc;
var aniCaption;

function animation( href, src, caption, width, height, animate )
{
	if( aniBlock )
	{
		return;
	}
		
	aniHref		= href;
	aniSrc		= src;
	aniCaption	= caption;
	
	// this is the case for browsers that don't support filters...
	var cycle	= Math.floor( Math.random() * href.length );

	// switch off animation if we're not on broadband
	var m_animation	= ( typeof(animate) != "undefined" ? animate : hasBroadband() );				
	if( m_animation == false || src.length <= 1 || !isDHTML )
	{
		document.writeln( animationPicker( cycle ) );
		return;
	}
	
	// go build all of the nested DIVs out
	aniIdx		= cycle;
	
	var nextImage	= (aniIdx + 1) % src.length;

	if( height > 0 ) { document.writeln( "<div id=\"container\" style=\"width:" + width +"px;height:" + height + "px\">" ); }
	else { document.writeln( "<div id=\"container\" style=\"width:" + width +"px\">" ); }

	for( i = 0; i < src.length; i++ )
	{
		// set up a placeholder
		document.write( "<div id=\"animation" + i + "\" style=\"display:none\">" );
		
		if( i == nextImage )
		{
			// only prefetch the first image we will display
			document.write( animationPicker( i ) );
		}
		
		document.write( "</div>" );
	}

	document.writeln( "</div>" );

	// pull the images out
	aniBlock	= new Array( src.length );
	aniImg		= new Array( src.length );

	for( i = 0; i < src.length; i++ )
	{
		aniBlock[i]	= document.getElementById( "animation" + i );
		
		if( i == nextImage )
		{
			aniImg[i] = document.getElementById( "aniimg" + i );
		}
		else
		{
			aniImg[i] = null;
		}
	}

	aniContainer = document.getElementById("container");
	
	animationEffects();
}

function animationEffects()
{
	var nextImage	= (aniIdx + 1) % aniImg.length;
	
	// run the transition	
	if( checkIEVer() >= 4.0 && aniEffect > 0 )
	{
		try
		{
			if( aniEffect == 1 )
			{
				aniContainer.style.filter = "blendTrans(duration=0.6)";
				aniContainer.filters(0).apply();
 				animationSelect( nextImage );
				aniContainer.filters(0).play();
			}
			else
			{
				aniContainer.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.0,transition=7)";
				aniContainer.filters(0).apply();
				aniContainer.filters(1).apply();
 				animationSelect( nextImage );
				aniContainer.filters(0).play();
				aniContainer.filters(1).play();
			}
		}
		catch( e ) { animationSelect( nextImage ); }
	}
	else
	{
		animationSelect( nextImage );
	}

	// asked to be called again a little later
	setTimeout( "animationPrep()", aniTimeout - 1500 );
	setTimeout( "animationSwap()", aniTimeout );
}

function animationSelect( nextImage )
{
	aniBlock[aniIdx].style.display = "none";
	aniIdx = nextImage;
	aniBlock[aniIdx].style.display = "block";
}		

function animationPrep()
{
	// prefetch the next image if we don't already have it
	var nextImage	= (aniIdx + 1) % aniImg.length;

	if( !aniImg[nextImage] )
	{
		aniBlock[nextImage].innerHTML = animationPicker( nextImage );
		aniImg[nextImage] = document.getElementById( "aniimg" + nextImage );
	}
}

function animationSwap()
{
	if( aniImg[aniIdx].complete )
	{
		// move the image index along
		animationEffects();
	}
	else
	{
		// check again 3 seconds later
		setTimeout( "animationSwap()", 3000 );
	}
}

function animationPicker( cycle )
{
	var divHtml;

	if( aniHref[cycle] != null ) 
	{
		divHtml = "<A href=\"" + aniHref[cycle] + "\"><IMG src=\"" + aniSrc[cycle] + "\" alt=\"" + aniCaption[cycle] + "\" BORDER=\"0\" ID=\"aniimg" + cycle + "\"></a>";
	}
	else
	{
		divHtml = "<IMG src=\"" + aniSrc[cycle] + "\" ID=\"aniimg" + cycle + "\">";
	}
	
	return divHtml;
}

function hasBroadband()
{
	if( checkIEVer() < 5.0 )
	{
		return false;
	}
	
	try
	{
		document.body.addBehavior ("#default#clientCaps");
	
		return ( typeof(document.body.connectionType) != "undefined" && document.body.connectionType == "lan" );
	}
	catch( e )
	{
		return false;
	}
}



