//
// montage_banners.js
//

var monImg_banners		= null;
var monAlt_banners		= null;
var monLnk_banners		= null;
var monIdx_banners		= 0;



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;

// initialize upon load to let all browsers establish content objects
function autoconfig_banners()
{
    if(document && document.images)
    {
        isCSS		= (document.body && document.body.style) ? true : false;
        isW3C		= (isCSS && document.getElementById) ? true : false;
        isIE4		= (isCSS && document.all && readIEVer_banners() >= 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 && readIEVer_banners() >= 6.0 );
        isDHTML		= isCSS && ( isIE4 || isGecko || isOpera );
        
        if( suppressMenus || ( isOpera && readOperaVer_banners() < 7 ) || ( isGecko && navigator.productSub <= 20011022 ) || ( isGecko && navigator.productSub == 20030107 ) )
        {
			// Opera 6.x doesn't seem to like the DHTML...
			// Netscape 6.2 puts the menus in the wrong place...
			// Safari, the menus don't go away... problem in ResetMenu
			isDHTML	= false;
        }
    }
}



function readIEVer_banners()
{
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "MSIE" );
	if( offset < 0 )
	{
		return 0;
	}
	return parseFloat( agent.substring( offset + 5, agent.indexOf( ";", offset ) ) );
}

function readOperaVer_banners()
{
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "Opera" );
	if( offset < 0 )
	{
		return 0;
	}
	return parseFloat( agent.substring( offset + 6 ) );
}





function montageEffects_banners()
{
	var container_banner	= document.getElementById("container_banner");
	var html		= "<a href=\"" + monLnk_banners[monIdx_banners] + "\"><img src=\"" + monImg_banners[monIdx_banners].src + "\" alt=\"" + monAlt_banners[monIdx_banners] + "\" border=\"0\"></a>";
	
	// simple case where there's only one thing in the rotation... and no transitions
	if( monImg_banners.length <= 1 )
	{
		container_banner.innerHTML = html;
		return;
	}

	// run the transition
	if( readIEVer_banners() >= 4.0 )
	{
		container_banner.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.0,transition=7)";
		container_banner.filters(0).apply();
		container_banner.filters(1).apply();
		container_banner.innerHTML = html;
		container_banner.filters(0).play();
		container_banner.filters(1).play();
	}
	else
	{
		container_banner.innerHTML = html;
	}

	// asked to be called again in 14 seconds
	setTimeout( "montageSwap_banners()", 14000 );
}

function montageSwap_banners()
{
	if( monImg_banners[monIdx_banners].complete )
	{
		// move the image index along
		monIdx_banners			= (monIdx_banners + 1) % monImg_banners.length;
		
		montageEffects_banners();
	}
	else
	{
		// check again 6 seconds
		setTimeout( "montageSwap_banners()", 6000 );
	}
}

function montage_banners( 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" || ( typeof(m_montage) != "undefined" && m_montage == false ) )
	{
		picker_banners( href, src, caption, cycle );
		return;
	}

	if( isIE4 || isW3C )
	{
		monLnk_banners		= href;
		monImg_banners		= new Array( src.length );
		monAlt_banners		= caption;
		
		// get just the first image right now...
		img = new Image( width );
			
		// pick a random image to start from
		monIdx_banners = cycle;
		
		img.src		= src[monIdx_banners];
		img.border	= 0;
		monImg_banners[monIdx_banners]	= img;

		// set up a placeholder
		document.write( "<div id=\"container_banner\" style=\"width:" + width +"px;height:60px\"></div>" );
	
		// switch in the first image
		montageEffects_banners();

		// 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_banners[i]	= img;
			}
		}		

		return;
	}
	
	picker_banners( href, src, caption, cycle );
}

function picker_banners( 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 montage_banners.js
// -------------------------------------------------------------

