
// BROWSER DETECTION

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 legacyMode		= false;
var timerID			= null;
var subtimerID		= null;

function browserDetection() {
    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 ((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 ) ) );
}

function readOperaVer() {
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "Opera" );
	if( offset < 0 ) {
		return 0;
	}
	return parseFloat( agent.substring( offset + 6 ) );
}


// JAVASCRIPT SLIDESHOW 

var gsSlideID = 0;
var gaBlockStyles  = null;
var gaSlideImages  = null;
var gaContainers   = null;
var giSlideTimeout = 3000;

function slides (href,src,caption,width,animate) {

	// this is the case for browsers that don't support filters...
	var liCycler	= 4; //Math.floor( Math.random() * href.length );
	// switch off animation if we're not on broadband
	var lbSlideshow	= true;//( typeof(animate) != "undefined" ? animate : ADSLconnection() );
	if (lbSlideshow == false || src.length <= 1 || !(isIE4||isW3C)) {
	
		slidePicker (href,src,caption,Math.floor( Math.random() * src.length ));
		return;
	}
	// build DIVs
	gsSlideID = liCycler;
	document.writeln( "<div id=\"container\" style=\"width:" + width +"px;height:188px\">" );

	// create placeholders
	for( i = 0; i < src.length; i++ ) {
		document.writeln( "\t<div id=\"montage" + i + "\" style=\"display:none\">" );
		slidePicker( href, src, caption, i );
		document.writeln( "\t</div>" );
	}
	document.writeln( "</div>" );

	// place images
	gaBlockStyles	= new Array(src.length);
	gaSlideImages		= new Array(src.length);
	for( i = 0; i < src.length; i++ ) {
		gaBlockStyles[i]	= document.getElementById( "montage" + i ).style;
		gaSlideImages[i]	= document.getElementById( "gaSlideImages" + i );
		if( gaSlideImages[i] == null ) {
			slidePicker( href, src, caption, i );
			return;
		}
	}
	gaContainers = document.getElementById("container");
	slideEffects();
}

function slideEffects() {
	var nextImage	= (gsSlideID + 1) % gaSlideImages.length;
	if( readIEVer() >= 4.0 ) {
		gaContainers.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.0,transition=6)";
		gaContainers.filters(0).apply();
		gaContainers.filters(1).apply();
 		slideSelection( nextImage );
		gaContainers.filters(0).play();
		gaContainers.filters(1).play();
	} else {
		slideSelection( nextImage );
	}
	setTimeout( "slideTransition()", giSlideTimeout );
}

function slideSelection (nextImage) {
	gaBlockStyles[gsSlideID].display = "none";
	gsSlideID = nextImage;
	gaBlockStyles[gsSlideID].display = "block";
}		

function slideTransition() {
	if( gaSlideImages[gsSlideID].complete ) {
		slideEffects(); // move the image index
	} else {
		setTimeout( "slideTransition()", 3000 ); // wait a little and check again
	}
}

function slidePicker (href,src,caption,liCycler) {
	if (href[liCycler]!= null) {
		document.writeln( "\t\t<A HREF=\"" + href[liCycler] + "\"><IMG SRC=\"" + src[liCycler] + "\" alt=\"" + caption[liCycler] + "\" BORDER=\"0\" ID=\"gaSlideImages" + liCycler + "\"></a>" );
	} else {
		document.writeln( "\t\t<IMG SRC=\"" + src[liCycler] + "\" ID=\"gaSlideImages" + liCycler + "\">" );
	}
}

function ADSLconnection() {
	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;
	}
}
