oFaders=new Object();
API.faders=oFaders;

oFaders.length=0;
oFaders.New=function(faderElement,faderTrans,faderFreq,startOpacity,endOpacity,fadeOutFakeOpacity) {
	API.faders[this.length]=new Fader(this.length,faderElement,faderTrans,faderFreq,startOpacity,endOpacity,fadeOutFakeOpacity);
	this.length++;
	return API.faders[this.length-1];

}
oFaders.Get=function(id) {
	for(i=0;i<this.length;i++) {
		if(API.faders[i].id==id) {
			return API.faders[i];
		}
	}
	return false;
}

function Fader(id,faderElement,faderTrans,faderFreq,startOpacity,endOpacity,fadeOutFakeOpacity) {
	this.element=faderElement;
	this.id=id;
	this.element.fader=this;
	this.interval=null;
	this.fadeOutFakeOpacity=fadeOutFakeOpacity;
	if(startOpacity)
		this.startOpacity=startOpacity;
	else
		this.startOpacity=0;

	if(endOpacity)
		this.endOpacity=endOpacity;
	else
		this.endOpacity=100;

	this.opacity=this.startOpacity;//100;
	this.opacityChange=this.endOpacity-this.startOpacity;

	if(faderTrans)
		this.trans=faderTrans*1000;
	else
		this.trans=500;

	if(faderFreq)
		this.freq=faderFreq;
	else
		this.freq=50;
	this.cancel=function() {
		if(this.interval)
			window.clearInterval(this.interval);
	}
	this.setOpacity=function() {
		if(this.opacity>this.endOpacity)
			this.opacity=this.endOpacity;
		if(this.opacity<this.startOpacity)
			this.opacity=this.startOpacity;
	    // IE/Win
		try {
			this.element.style.filter = "alpha(opacity:"+this.opacity+")";
	    }
		catch(e) {
		}
	    // Safari<1.2, Konqueror
		try {
			this.element.style.KHTMLOpacity = this.opacity/100;
		}
		catch(e) {
		}
	    // Older Mozilla and Firefox
		try {
			this.element.style.MozOpacity = this.opacity/100;
		}
		catch(e) {
		}
	    // Safari 1.2, newer Firefox and Mozilla, CSS3
		try {
			this.element.style.opacity = this.opacity/100;
		}
		catch(e) {
		}
	}
	this.fadeIn=function(fading) {
		if(this.interval)
			window.clearInterval(this.interval);
			/*
		if(!fading) {
			this.opacity=0;
			this.setOpacity();
		}
		*/
		
		// BF/BC20081117:	Using inline display could break "a lot" 
		if(this.element.style.display=='none')
			this.element.style.display='block';

		this.opacity=this.opacity + this.opacityChange / (this.trans/this.freq);
		this.setOpacity();
		if(this.opacity!=this.endOpacity)
			this.interval=window.setInterval('API.faders['+this.id+'].fadeIn(true);',this.freq);
	}
	this.fadeOut=function() {
		if(this.interval)
			window.clearInterval(this.interval);
			/*
		if(this.element.style.display!='none') {
			this.opacity=100;
		}
		*/
		this.opacity=this.opacity -this.opacityChange / (this.trans/this.freq);
		if(!this.fadeOutFakeOpacity)
			this.setOpacity();
		if(this.opacity>this.startOpacity)
			this.interval=window.setInterval('API.faders['+this.id+'].fadeOut(true);',this.freq);
		else {
			//this.opacity=100;
			this.setOpacity();
			if(this.opacity==0)
				this.element.style.display='none';

		}
	}
}