var hshFaders = [];

function Fader( strObjName ) {
	this.strObjName = strObjName;
	this.objElement = null;
	
	this.intResolution = 5;  // in %points
	this.intInterval = 25;   // in msec
	this.intPauseInterval = 1500;   // in msec
	this.intOpacity = 0;
	
	this.blnFadeIn = true;
	this.blnPause = true;
	this.clock = null;
}


Fader.prototype.fade = function( intX, intY, strMessage ) {
	
	this.objElement = document.createElement("div");
	this.objElement.className = "faderPanel";
	// some basic styling
	this.objElement.style.zIndex = "10000";
	this.objElement.style.position = "absolute";
	this.objElement.style.top = (intY - 15) + "px";
	this.objElement.style.left = (intX + 10) + "px";
	// insert the message
	this.objElement.innerHTML = strMessage;

	this.intOpacity = 0;
	this.setOpacity();

	var objBodyElement = objDOM.getLayerReference( 'pageBody' );
	objBodyElement.appendChild(this.objElement);
	

	this.doFade();
	if (this.clock == null)
	{
		//start the timer
		this.clock = setInterval( this.strObjName + ".doFade()", this.intInterval );
	}	
}
Fader.prototype.killFade = function() {
	if (this.clock != null)
	{
		// stop the fade...
		clearInterval( this.clock );
		this.clock = null;
		
		// back to hidden...
		this.intOpacity = 0;
		this.setOpacity();
	}
}

Fader.prototype.doFade = function() {

	// increment or decrement the opacity
	if (this.blnFadeIn) {
		this.intOpacity = this.intOpacity + this.intResolution;
	} else {
		this.intOpacity = this.intOpacity - this.intResolution;
	}
	
		
	//if the opacity has reached the top
	if ( this.intOpacity >= 100 )
	{
		//clear the timer
		clearInterval( this.clock );
		this.clock = null;

		
		if ( this.blnPause )
		{
			// only pause once
			this.blnPause = false;
			
			//restart the timer with the pause time
			this.clock = setInterval( this.strObjName + ".doFade()", this.intPauseInterval );
		}
		else
		{
			//reverse the fade direction flag
			this.blnFadeIn = false;
			
			//restart the timer to start the fade out
			this.clock = setInterval( this.strObjName + ".doFade()", this.intInterval );
		}
	}
	
	//if the opacity has reached the bottom
	if ( this.intOpacity <= 0 )
	{
		//clear the timer
		clearInterval( this.clock );
		this.clock = null;

		//reset the fade direction back to original
		this.blnFadeIn = true;
		
		//reset the opacity
		this.intOpacity = 0;
	}

	// knock down to just under a hundred to avoid a Mozilla bug
	this.intOpacity = (this.intOpacity >= 100) ? 99.999 : this.intOpacity;
	this.setOpacity();
	
}

Fader.prototype.setOpacity = function() {
	// IE/Win
	this.objElement.style.filter = "alpha(opacity:"+this.intOpacity+")";
	// Safari< 1.2, Konqueror
	this.objElement.style.KHTMLOpacity = this.intOpacity/100;
	// Older Mozilla and Firefox
	this.objElement.style.MozOpacity = this.intOpacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	this.objElement.style.opacity = this.intOpacity/100;
}



