Fade = {
	To: function(obj, finalValue)
	{
		var fader = new Fader(obj, finalValue);
	},
	SetOpacity: function(obj, opacity)
	{
		var opacity_IE = Math.round(opacity * 100);
		obj.style.opacity = opacity.toString();
		obj.style.filter = 'alpha(opacity=' + opacity_IE.toString() + ')';
	}
};

function Fader(obj, finalValue)
{
	this.obj = obj;
	this.finalValue = finalValue;
	//
	if(this.obj.Fader != null && this.obj.Fader.timer != null)
		window.clearTimeout(this.obj.Fader.timer);
	//
	this.guid = 'FadeTo_' + Math.random().toString().substring(2);
	//
	this.timer = null;
	this.timeout = 30;
	this.step = 0.05;
	//
	if (this.obj.style.opacity == null || this.obj.style.opacity == '')
	{
		this.obj.style.opacity = '1';
		this.obj.style.filter = 'alpha(opacity=100)';
	}
	//
	eval('window.' + this.guid + '=this');
	this.NextStep();
	//
	this.obj.Fader = this;
};

Fader.prototype.NextStep = function()
{
	//
	var currentValue = Number(this.obj.style.opacity);
	currentValue = Math.round(currentValue * 100) / 100;

	if (currentValue != this.finalValue)
	{
		var tempVal = null;
		if (Math.abs(Math.abs(currentValue) - Math.abs(this.finalValue)) < this.step)
			tempVal = this.finalValue;
		else
			tempVal = (currentValue < this.finalValue) ? (currentValue + this.step) : (currentValue - this.step);
		//
		Fade.SetOpacity(this.obj, tempVal);
		//
		this.timer = window.setTimeout('window.' + this.guid + '.NextStep()', this.timeout);
	}
};
