////////////////////////  Browser detector class
function BrowserDetector( ua /* ua = User Agent */ ) {
	// Default values
	this.browser = "Unknown";
	this.platform = "Unknown";
	this.version = "";
	this.majorver = "";
	this.minorver = "";

	uaLen = ua.length;

	// Split into stuff before parens and stuff in parens
	var preparens = "";
	var parenthesized = "";
	var operaFix = ua.indexOf( "Opera" ) > 0;

	i = ua.indexOf( "(" );
	if( i >= 0 ) {
		preparens = Trim( ua.substring( 0,i ) );
		parenthesized = ua.substring( i + 1, uaLen );
		j = parenthesized.indexOf( ")" );

		if( j >= 0 ) 
			parenthesized = parenthesized.substring(0, j);
	}
	else 
		preparens = ua;
  
	// First assume browser and version are in preparens
	// override later if we find them in the parenthesized stuff
	var browVer = preparens;
	var tokens = parenthesized.split( ";" );
	var token = "";

	// Now go through parenthesized tokens
	for( var i = 0; i < tokens.length; i++ ) {
		token = Trim( tokens[i] );
        // compatible - might want to reset from Netscape
        if( token == "compatible" ) {
			// One might want to reset browVer to a null string
			// here, but instead, we'll assume that if we don't
			// find out otherwise, then it really is Mozilla
			// (or whatever showed up before the parens).
			// browser - try for Opera or IE
		}
        else if( token.indexOf( "MSIE" ) >= 0 ) 
        	browVer = token;
		else if( token.indexOf( "Opera" ) >= 0 ) 
			browVer = token;
		//platform - try for X11, SunOS, Win, Mac, PPC
		else if( ( token.indexOf( "X11" ) >= 0 ) || 
				 ( token.indexOf( "SunOS" ) >= 0 ) ||
				 ( token.indexOf( "Linux" ) >= 0 ) ) 
			this.platform = "Unix";
        else if( token.indexOf( "Win" ) >= 0 ) 
        	this.platform = token;
        else if( ( token.indexOf( "Mac" ) >= 0 ) || ( token.indexOf( "PPC" ) >= 0 ) ) 
        	this.platform = token;        
	}

	var msieIndex = browVer.indexOf( "MSIE" );
	if( msieIndex >= 0 )
		browVer = browVer.substring( msieIndex, browVer.length );
	
	var leftover = "";
  
	if( !operaFix && browVer.substring( 0, "Mozilla".length ) == "Mozilla" ) {
		this.browser = "Netscape";
        leftover = browVer.substring( "Mozilla".length + 1, browVer.length );
	}
	else if( !operaFix && browVer.substring( 0, "Lynx".length ) == "Lynx" ) {
		this.browser = "Lynx";
        leftover = browVer.substring( "Lynx".length + 1, browVer.length );
	}
	else if( !operaFix && browVer.substring( 0, "MSIE".length ) == "MSIE" ) {
		this.browser = "IE";
		leftover = browVer.substring( "MSIE".length + 1, browVer.length );
	}
	else if( !operaFix && 
		browVer.substring( 0, "Microsoft Internet Explorer".length ) ==	"Microsoft Internet Explorer" ) 
	{
		this.browser = "IE"
        leftover = browVer.substring( "Microsoft Internet Explorer".length + 1, browVer.length );
	}
	else if( operaFix || browVer.substring( 0, "Opera".length ) == "Opera" ) {
		this.browser = "Opera";
		if( operaFix )
			leftover = browVer.substring( "MSIE".length + 1, browVer.length );
		else
			leftover = browVer.substring( "Opera".length + 1, browVer.length );
	}

	leftover = Trim(leftover);

	// Try to get version info out of leftover stuff
	i = leftover.indexOf( " " );
	if( i >= 0 ) 
		this.version = leftover.substring( 0, i );
	else
		this.version = leftover;
	
	j = this.version.indexOf( "." );
	if( j >= 0 ) {
		this.majorver = this.version.substring( 0,j );
		this.minorver = this.version.substring( j + 1, this.version.length );
	}
	else 
		this.majorver = this.version;	
}

/* NETSCAPE FIX RESIZE BUG NS4 **************************************/
function WM_netscapeCssFix() {
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth ||
        document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
     document.location = document.location;
    }
}

function WM_netscapeCssFixCheckIn() {
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
       document.WM = new Object;
       }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
       document.WM.WM_netscapeCssFix = new Object;
       document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
       document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
       }
    window.onresize = WM_netscapeCssFix;
  }
}

WM_netscapeCssFixCheckIn();

//  Utility function to trim spaces from both ends of a string//////////////////////////////
function Trim(inString) {
	var retVal = "";
	var start = 0;
	
	while( (start < inString.length) && (inString.charAt(start) == ' ') ) 
		++start;
	
	var end = inString.length;
	
	while( (end > 0) && (inString.charAt(end - 1) == ' ') ) 
		--end;
	
	retVal = inString.substring( start, end );
	return retVal;
}
/*********************************************************************************/
	function toggle(id) {
		if (document.all(id).style.display == '') { document.all(id).style.display = 'none'; }
		else { document.all(id).style.display = ''; }
	}



///////////////////////////////////////////////////////////////////////
//     This fade library was designed by Erik Arvidsson for WebFX    //
//                                                                   //
//     For more info and examples see: http://webfx.eae.net          //
//     or contact Erik at http://webfx.eae.net/contact.html#erik     //
//                                                                   //
//     Feel free to use this code as long as this disclaimer is      //
//     intact.                                                       //
//                                                                   //
//     Last updated: 2000-11-22                                      //
///////////////////////////////////////////////////////////////////////
	
var fadeSteps = 16;				// Number of steps to loop
var fademsec = 25;				// The time between each step (note that most computer have problem
								// handling to small values due to hardware limitations)
								
var interval = 5000;			// Interval between segments
var divIndex = 0;
var arrayLength = 0;

var bd = new BrowserDetector(navigator.userAgent); 
var supportFade = ( bd.browser == "IE" && bd.version >= "5.5" );

divArray = new Array();						

var rotatorIndex = 0;
rotatorArray = new Array();

window.status = "Loading fade package";

var fadeArray = new Array();	// Needed to keep track of wich elements are animating

//////////////////  fade  ////////////////////////////////////////////////////////////
//                                                                                  //
//   parameter: fadeIn                                                              //
// description: A boolean value. If true the element fades in, otherwise fades out  //
//              The steps and msec are optional. If not provided the default        //
//              values are used                                                     //
//                                                                                  //
//////////////////////////////////////////////////////////////////////////////////////

function fade(el, fadeIn, steps, msec) {

	if (steps == null) steps = fadeSteps;
	if (msec == null) msec = fademsec;
	
	if (el.fadeIndex == null)
		el.fadeIndex = fadeArray.length;
	fadeArray[el.fadeIndex] = el;
	
	if (el.fadeStepNumber == null) {
		if (el.style.display == "none")
			el.fadeStepNumber = 0;
		else
			el.fadeStepNumber = steps;
		if (fadeIn) {
			el.style.filter = "Alpha(Opacity=0)";
			el.style.MozOpacity = 0;
		}
		else {
			el.style.filter = "Alpha(Opacity=100)";
			el.style.MozOpacity = 1;
		}
	}
			
	window.setTimeout("repeatFade(" + fadeIn + "," + el.fadeIndex + "," + steps + "," + msec + ")", msec);
}

////////////////////////////////////  Used to iterate the fading
function repeatFade(fadeIn, index, steps, msec) {	
	el = fadeArray[index];
	c = el.fadeStepNumber;
	if (el.fadeTimer != null)
		window.clearTimeout(el.fadeTimer);
		
	if ((c == 0) && (!fadeIn)) {			//Done fading out!
		el.style.display = "none";		// If the platform doesn't support filter it will hide anyway
		el.style.filter = "";
		return;
	}
	else if ((c==steps) && (fadeIn)) {	//Done fading in!
		el.style.filter = "";
		el.style.MozOpacity = 1;
		el.style.display = "";
		return;
	}
	else {
		(fadeIn) ? 	c++ : c--;
		el.style.display = "";
		el.style.filter = "Alpha(Opacity=" + 100*c/steps + ")";
		el.style.MozOpacity = c / steps;

		el.fadeStepNumber = c;
		el.fadeTimer = window.setTimeout("repeatFade(" + fadeIn + "," + index + "," + steps + "," + msec + ")", msec);
	}
}

function fadeOut(obj) {
	obj.style.filter="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=0.25,wipestyle=0,motion=forward)";//"blendTrans(duration=1)";
	if( obj.filters[0].status != 2 ) // Make sure filter is not playing
	{
		obj.filters[0].apply(); // blendTrans
		obj.style.visibility="hidden";
		obj.filters[0].play();
	}
}

function fadeIn(obj) {
	obj.style.filter="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=0.25,wipestyle=0,motion=forward)";//"blendTrans(duration=1)";
	if( obj.filters[0].status != 2 ) // Make sure filter is not playing -- .blendTrans
	{
		obj.filters[0].apply();		// .blendTrans
		obj.style.visibility="visible";
		obj.filters[0].play();
	}
}

///////////////////////// SegmentRotator object constructor
function segmentRotator( rotatorId, segmentInterval ) {
	// object properties
	this.rotatorId = rotatorId;
	this.segmentInterval = segmentInterval;

	this.divIndex = 0;
	this.arrayLength = 0;
	this.divArray = new Array();
	this.rotatorIndex = rotatorIndex;

	this.initialize = segmentRotator_initialize;
	this.rotate = segmentRotator_rotateSegments;

	rotatorArray[rotatorIndex++] = this;
}

	function segmentRotator_initialize() {
		var rotator = document.getElementById( this.rotatorId + "_Rotator" );
		if( rotator != null ) {
			this.divArray[this.divIndex++] = document.getElementById( this.rotatorId + "0" );
			while( this.divArray[this.divIndex - 1] != null )
			{
				var o = document.getElementById( this.rotatorId + this.divIndex );
				if( o == null )
					break;

				this.divArray[this.divIndex++] = o;
			}
		}

		this.arrayLength = this.divArray.length;
		this.divIndex = 0;

		setTimeout( "segmentRotator_rotateSegments(" + this.rotatorIndex + ")", this.segmentInterval );
	}

	function segmentRotator_rotateSegments( rIndex ) {
		rot = rotatorArray[rIndex];
		if( rot == null )
			return;

		if( supportFade )
			fadeOut(rot.divArray[rot.divIndex]);
		else
			fade(rot.divArray[rot.divIndex], false);

		rot.divIndex = (rot.divIndex + 1) % rot.arrayLength;

		if( supportFade )
			fadeIn(rot.divArray[rot.divIndex]);
		else
			fade(rot.divArray[rot.divIndex], true);

//alert('::' + rot.divArray[rot.divIndex].id + '::');
		setTimeout( "segmentRotator_rotateSegments(" + rIndex + ")", rot.segmentInterval );
	}

/*
function rotate(rotatorId, segInterval)
{	
		interval = segInterval;
	var rotator = document.getElementById(rotatorId + "_Rotator");
	if( rotator != null )
	{		
		divArray[divIndex++] = document.getElementById(rotatorId + "0");
		while( divArray[divIndex-1] != null )
		{
			o = document.getElementById( rotatorId + divIndex );
			if( o == null )
				break;
				
			divArray[divIndex++] = o;
		}
	}
	
	arrayLength = divArray.length;
	divIndex = 0;

	rotateSegments();
}

function rotateSegments()
{	
	if( supportFade )
		fadeOut(divArray[divIndex]);
	else
		fade(divArray[divIndex], false); 
	
	divIndex = (divIndex + 1) % arrayLength;
	
	if( supportFade )
		fadeIn(divArray[divIndex]);
	else
		fade(divArray[divIndex], true); 
	
	setTimeout( "rotateSegments()", interval );
}*/

window.status = "";


