// create a Loader object and set it to run at window.onload
var loader= new Loader();

// if we don't support DOM-2, we'll need to tell the browser to run our loader
// object on window.onload...
if (!window.addEventListener)
{
	window.onload= _Loader_InvokeLoaderRun;
}

// ...and here's the function that will run the loader object
function _Loader_InvokeLoaderRun()
{
	loader.run();
}


/*-----------------------------------------------------------------------------
Loader: class to handle window.onload functions
-----------------------------------------------------------------------------*/
function Loader()
{
	// register public methods
	this.add= _Loader_Add;
	this.run= _Loader_Run;
	this.toString= _Loader_ToString;
}


// private
// add a function to be run at window load
function _Loader_Add(ivalue)
{
	if (ivalue)
	{
		// if we support the DOM-2 event model
		if (window.addEventListener)
		{
			window.addEventListener("load", ivalue, false);
		}

		// else we'll add this function to the loader function list
		else
		{
			if (!this._functionList)
			{
				this._functionList= new Array();
			}
	
			// using Array.push() limits to JavaScript 1.2 and above
			if (this._functionList.push)
			{
				this._functionList.push(ivalue);
			}
		}
	}
}


// private
// run the loader functions for browsers that don't support DOM-2
function _Loader_Run()
{
	if (this._functionList)
	{
		for (var i= 0; i < this._functionList.length; i++)
		{
			this._functionList[i]();
		}
	}
}


// private
// report this object as a Loader
function _Loader_ToString()
{
	return "Loader";
}

