//
// Animation that fades an element in or out
//
function tfx_fade(element, startOpacity, endOpacity, duration)
{
	this.complete = false;
	this.element = element;
	this.opacity = startOpacity;
	this.opacityEnd = endOpacity;
	this.step = (endOpacity - startOpacity) / ((duration * 1000) / tfx_animation.timerInterval);
	
//	document.body.appendChild(document.createTextNode("Step = " + this.step + " "));
	
	// ends the animation
	this.end = function()
	{
		tfx_animation.remove(this);
	}
	
	// executes an animation step
	this.execute = function()
	{
		this.opacity += this.step;
		this.setOpacity(this.opacity);

		if (this.step > 0 && this.opacity >= this.opacityEnd)
		{
			this.complete = true;
			this.opacity = this.opacityEnd;
		}
		else if (this.step < 0 && this.opacity <= this.opacityEnd)
		{
			this.complete = true;
			this.opacity = this.opacityEnd;
		}
	
		if (this.complete == true)
		{
			this.end();
		}
	}

	if (document.all)
	{
		this.setOpacity = function(value)
		{
			if (value <= 0.0) value = 0.0;
			if (value >= 1.0) value = 1.0;
			
			this.element.style.filter = "alpha(opacity=" + (100 * value) + ")";
		}
	}
	else if (document.getElementById)
	{
		this.setOpacity = function(value)
		{
			if (value <= 0.0) value = 0.00;
			if (value >= 1.0) value = 0.99;
			
			this.element.style.opacity = value;
		}
	}

	tfx_animation.add(this);
}

