
var fade_limit = 3;

function FadeObject(id)
{
	this.id = id;
	this.s = document.getElementById(id);
	
	this.fade_in = _obj_fade_in;
	this.fade_out = _obj_fade_out;

	this._fade_in = obj_fade_in;
	this._fade_out = obj_fade_out;

	this.fade_interval = null;
	
	this.speed = 20;
	
	this.function_ref = noop;
	
	this.fade_limit = 0;
	
	
	this.fade_out_delayed = obj_delay_fade;
}

function obj_delay_fade()
{
	var obj = this;
	window.setTimeout(function(event) { obj.fade_out(); }, 5000);	
}

function _obj_fade_in()
{
	var obj = this;
	this.fade_interval = window.setInterval(function(event) { obj._fade_in(); }, 150);
}

function _obj_fade_out()
{
	var obj = this;
	
	this.fade_interval = window.setInterval(function(event) { obj._fade_out(); }, 150);
}

function obj_fade_out()
{
	var b = this.s;
	
	var fade_limit = this.fade_limit;
	
	//alert(fade_limit);
	
	if ( isNaN(fade_limit) )
	{
		fade_limit = 0;
	}
	
	if ( b != null )
	{
		if ( b.style.opacity == "" ) b.style.opacity = "1";
		if ( document.all && b.style.filter == "" ) b.style.filter = "alpha(opacity=100)";

		//alert(b.style.opacity);

		if ( ( document.all && b.style.filter == "alpha(opacity=" +(fade_limit*this.speed)+ ")" ) || ( !document.all && b.style.opacity == (fade_limit/10) / this.speed ) )
		{
			
			clearInterval(this.fade_interval);
			
			this.function_ref();
		}
		else
		{
			if ( document.all )
			{
				(b.style.filter+ "").match(/alpha\(opacity=(\d+)\)/);
				var i = parseInt(RegExp.$1);
				i -= this.speed;
				
				b.style.filter = "alpha(opacity=" +i+ ")";
			}
			else
			{
				var i = b.style.opacity;
				b.style.opacity = parseFloat(i) - this.speed/100;
			}
		}	
	}	
}

function obj_fade_in()
{
	var b = this.s;
	
	if ( b != null )
	{
		if ( b.style.opacity == "" ) b.style.opacity = "0.3";
		if ( document.all && b.style.filter == "" ) b.style.filter = "alpha(opacity=30)";
	
		if ( ( document.all && b.style.filter == "alpha(opacity=100)" ) || ( !document.all && b.style.opacity == "1" ) )
		{
			clearInterval(this.fade_interval);
			
			this.function_ref();
		}
		else
		{
			if ( document.all )
			{
				(b.style.filter+ "").match(/alpha\(opacity=(\d+)\)/);
				var i = parseInt(RegExp.$1);
				i += this.speed;
				
				b.style.filter = "alpha(opacity=" +i+ ")";
			}
			else
			{
				var i = b.style.opacity;
				b.style.opacity = parseFloat(i) + this.speed/100;
			}
		}	
	}	
}

