//
// LoadEvent.js
// 
// Pass functions to LoadEvent() to add them to the list to be loaded by onload event
// Add online="LoadEvent();" to body tag
//
// (c) 2007-2009 Yvan Rodrigues http://www.yvanrodrigues.com
//

// make an array of events to load onLoad
var LoadEvents = new Array();
// this indicates if onload has been fired and LoadEvents completed
var OnLoaded = false;


// No arguments = run!
// DoThis = function to add to list
// top = add to TOP of list
function LoadEvent(DoThis, top)
{
    // if param is passed then we're adding to the list
    top = typeof (top) == 'undefined' ? false : top;
    if (typeof (DoThis) == 'function') 
    {
        if (top) LoadEvents.unshift(DoThis);
        else LoadEvents.push(DoThis);
    }
    // otherwise we're running the events
	if(typeof(DoThis) == 'undefined' && !OnLoaded)
	{
	    for(ev in LoadEvents)
            LoadEvents[ev]();
		OnLoaded = true;
	}
}