///////////////////////////////////////////////////////////////////////
//     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); 
		
		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 = "";

