/*-----------------------------------------------------------------------------
ZapLoader.js

	ZapLoader.js: emulates the DOM-2 addEventListener ability to add multiple
	events to the onload event of the Window object

	If you decide to use ZapLoader, make sure it is the very first piece
	of JavaScript on your page!

-----------------------------------------------------------------------------*/
// Create a ZapLoader object
var zapLoader= new ZapLoader();

// if we don't support DOM-2, we'll need to tell the browser to run the
// ZapLoader object on window.onload...
if (!window.addEventListener)
{
	window.onload= _ZapLoader_InvokeLoaderRun;
}

// ...and here's the function that will run the ZapLoader object
function _ZapLoader_InvokeLoaderRun()
{
	zapLoader.run();
}


/*-----------------------------------------------------------------------------
ZapLoader: class to handle window.onload functions

	Designed to work with JavaScript 1.2 and above but should happily
	co-exist with previous versions (though the ZapLoader won't do
	anything on older versions - which is a good thing!)
-----------------------------------------------------------------------------*/
function ZapLoader()
{
	// register methods
	this.add= _ZapLoader_Add;
	this.run= _ZapLoader_Run;
	this.toString= _ZapLoader_ToString;
}


// add a function to the loader function list
function _ZapLoader_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);
			}
		}
	}
}


// run the loader functions
function _ZapLoader_Run()
{
	if (this._functionList)
	{
		for (var i= 0; i < this._functionList.length; i++)
		{
			this._functionList[i]();
		}
	}
}


// report this object as a ZapLoader
function _ZapLoader_ToString()
{
	return "ZapLoader";
}