function FadeCover( sCanvas, sFader, nStep, nDelay, nOpacityInit  )
{
	this.init( sCanvas, sFader, nStep, nDelay, nOpacityInit  );
};

FadeCover.prototype.init = function( sCanvas, sFader, nStep, nDelay, nOpacityInit )
{
	window[ ( this._self = "FadeCoverObject" ) ] = this;
	this._timer   = null;
	this._step    = nStep != null ? parseInt( nStep ) : 10;
	this._delay   = nDelay != null ? parseInt( nDelay ) : 30;
	this._canvas  = document.getElementById( sCanvas );
	this._fader   = document.getElementById( sFader );
	this._opacity = nOpacityInit != null ? parseInt( nOpacityInit ) : 100;
};

FadeCover.prototype.fadein = function()
{
	clearTimeout( this._timer );

	var eLoading = document.getElementById( "loading" );
	if ( eLoading != null )
		eLoading.style.display = "none";

	this._fadestep( true );
};

FadeCover.prototype.fadeout = function()
{
	clearTimeout( this._timer );

	this._fadestep( false );
};

FadeCover.prototype._fadestep = function( bAdd )
{
	clearTimeout( this._timer );

	if ( !bAdd )
	{
		if ( this._opacity < 100 )
		{
			this._opacity += this._step;
			this._fader.style.opacity = this._opacity * .01;
			this._fader.style.filter  = "alpha(opacity=" + this._opacity + ")";
			this._timer = setTimeout( this._self + "._fadestep( " + bAdd + " );", this._delay );
		}
		else if ( typeof FadeoutComplete == "function" )
			FadeoutComplete();
	}
	else
	{
		if ( this._opacity >= 0 )
		{
			this._opacity -= this._step;
			this._fader.style.opacity = this._opacity * .01;
			this._fader.style.filter  = "alpha(opacity=" + this._opacity + ")";
			this._timer = setTimeout( this._self + "._fadestep( " + bAdd + " );", this._delay );
		}
		else if ( typeof FadeinComplete == "function" )
			FadeinComplete();
	}
};
