//
// montage.js
//
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()
{
    if(document && document.images)
    {
        isCSS		= (document.body && document.body.style) ? true : false;
        isW3C		= (isCSS && document.getElementById) ? true : false;
        isIE4		= (isCSS && document.all && readIEVer() >= 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() >= 6.0 );
        isDHTML		= isCSS && ( isIE4 || isGecko || isOpera );
        
        if( suppressMenus || ( isOpera && readOperaVer() < 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()
{
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "MSIE" );
	if( offset < 0 )
	{
		return 0;
	}
	return parseFloat( agent.substring( offset + 5, agent.indexOf( ";", offset ) ) );
}

//
// montage.js
//

var monBlock	= null;
var monImg		= null;
var monIdx		= 0;
var monContainer= null;
var monTimeout	= 3000;

function montage( href, src, caption, width, height ) {
	var animate = true;
	// 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_montage	= ( typeof(animate) != "undefined" ? animate : hasBroadband() );
	if( m_montage == false || src.length <= 1 || !( isIE4 || isW3C ) ) {
		montagePicker( href, src, caption, cycle );
		return;
	}
	
	// go build all of the nested DIVs out
	monIdx = cycle;
	document.writeln( "<div id=\"container\" class='bookimgright'>" );
	for( i = 0; i < src.length; i++ ) {
		// set up a placeholder
		document.writeln( "\t<div id=\"montage" + i + "\" style=\"display:none\">" );
		montagePicker( href, src, caption, i );
		document.writeln( "\t</div>" );
	}
	document.writeln( "</div>" );

	// pull the images out
	monBlock	= new Array( src.length );
	monImg		= new Array( src.length );
	for( i = 0; i < src.length; i++ ) {
		monBlock[i]	= document.getElementById( "montage" + i ).style;
		monImg[i]	= document.getElementById( "monimg" + i );
		if( monImg[i] == null ) {
			montagePicker( href, src, caption, i );
			return;
		}
	}
	monContainer = document.getElementById("container");
	montageEffects();
}

function montageEffects()
{
	var nextImage	= (monIdx + 1) % monImg.length;
	
	// run the transition
	if( readIEVer() >= 4.0 ) {
		monContainer.style.filter = "blendTrans(duration=0.9) revealTrans(duration=0.0,transition=12)";
		monContainer.filters(0).apply();
		monContainer.filters(1).apply();
 		montageSelect( nextImage );
		monContainer.filters(0).play();
		monContainer.filters(1).play();
	}
	else {
		montageSelect( nextImage );
	}

	// asked to be called again a little later
	setTimeout( "montageSwap()", monTimeout );
}

function montageSelect( nextImage )
{
	//alert( monImg[monIdx].style.visibility );
	monBlock[monIdx].display = "none";
	monIdx = nextImage;
	monBlock[monIdx].display = "block";
}		

function montageSwap()
{
	if( monImg[monIdx].complete )
	{
		// move the image index along
		montageEffects();
	}
	else
	{
		// check again 3 seconds later
		setTimeout( "montageSwap()", 2000 );
	}
}

function montagePicker( 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=\"monimg" + cycle + "\"></a>" );
	}
	else
	{
		document.writeln( "\t\t<IMG SRC=\"" + src[cycle] + "\" ID=\"monimg" + cycle + "\">" );
	}
}

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;
	}
}

//*********************************
//*********************************
//*********************************
var monBlock2 = null;
var monImg2 = null;
var monIdx2 = 0;
var monContainer2 = null;
var monTimeout2 = 3000;

function montage2( href, src, caption, width, height ) {
	var animate = true;
	// 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_montage	= ( typeof(animate) != "undefined" ? animate : hasBroadband() );
	if( m_montage == false || src.length <= 1 || !( isIE4 || isW3C ) ) {
		montagePicker2( href, src, caption, cycle );
		return;
	}
	
	// go build all of the nested DIVs out
	monIdx2 = cycle;
	document.writeln( "<div id=\"container2\" class='bookimg'>" );
	for( i = 0; i < src.length; i++ ) {
		// set up a placeholder
		document.writeln( "\t<div id=\"montage2" + i + "\" style=\"display:none\">" );
		montagePicker2( href, src, caption, i );
		document.writeln( "\t</div>" );
	}
	document.writeln( "</div>" );

	// 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 ) {
			montagePicker2( href, src, caption, i );
			return;
		}
	}
	monContainer2 = document.getElementById("container2");
	montageEffects2();
}

function montageEffects2() {
	var nextImage	= (monIdx2 + 1) % monImg2.length;
	
	// run the transition
	if( readIEVer() >= 4.0 ) {
		monContainer2.style.filter = "blendTrans(duration=0.9) revealTrans(duration=0.0,transition=12)";
		monContainer2.filters(0).apply();
		monContainer2.filters(1).apply();
 		montageSelect2( nextImage );
		monContainer2.filters(0).play();
		monContainer2.filters(1).play();
	}
	else {
		montageSelect2( nextImage );
	}
	// asked to be called again a little later
	setTimeout( "montageSwap2()", monTimeout2 );
}

function montageSelect2( nextImage ) {
	monBlock2[monIdx2].display = "none";
	monIdx2 = nextImage;
	monBlock2[monIdx2].display = "block";
}		

function montageSwap2() {
	if( monImg2[monIdx2].complete ) {
		// move the image index along
		montageEffects2();
	}
	else {
		// check again 3 seconds later
		setTimeout( "montageSwap2()", 2000 );
	}
}

function montagePicker2( 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=\"monImg2" + cycle + "\"></a>" );
	}
	else {
		document.writeln( "\t\t<IMG SRC=\"" + src[cycle] + "\" ID=\"monImg2" + cycle + "\">" );
	}
}
