//
// Animation that fades an element in or out
//
function FadeAnimation(element, startOpacity, endOpacity, duration)
{
	var instance = this;
	
	this.complete = false;
	this.element = element;
	this.endOpacity = endOpacity;
	this.startOpacity = startOpacity;
	this.t = 0;
	this.tStep = (duration != 0) ? (1 / Animation.fps) / duration: 1;
	this.timer = null;
	this.timerInterval = (1 / Animation.fps) * 1000;
	
	this.setOpacity(this.startOpacity);
}

FadeAnimation.prototype.execute = function()
{
	var instance = this;

	this.t += this.tStep;
	this.setOpacity((this.endOpacity - this.startOpacity) * this.t + this.startOpacity);

	if (this.t < 1.0)
	{
		instance.timer = setTimeout(function(){instance.execute()}, this.timerInterval);
	}
}

if (document.all)
{
	FadeAnimation.prototype.setOpacity = function(value)
	{
		if (value <= 0.0) value = 0.0;
		if (value >= 1.0) value = 1.0;
		
		this.element.style.display = value > 0 ? "block" : "none";
		this.element.style.filter = "alpha(opacity=" + (100 * value) + ")";
	}
}
else if (document.getElementById)
{
	FadeAnimation.prototype.setOpacity = function(value)
	{
		if (value <= 0.0) value = 0.00;
		if (value >= 1.0) value = 0.99;
		
		this.element.style.display = value > 0 ? "block" : "none";
		this.element.style.opacity = value;
	}
}

