/**********************************************************
Author:
Adam Barry
eBOUND
www.ebound.dk

Date: December 8 2008

© 2007 Adam Barry, all rights reserved

Inspiration: http://simonwillison.net/2004/May/26/addLoadEvent/
-----------------------------------------------------------

Name:
windowOnLoad script

-----------------------------------------------------------
Description:
Function that enables loading of multiple functions during
window.onload

-----------------------------------------------------------
Usage:
Simply place a link to the this script in the top of the
<head>-section of the XHTML page - before including
additional JavaScript files. The script will then
automatically execute on page load.

Include the addLoadEvent code in the scripts that you wish to have
loaded at the time of page-load according to the example below.

<script type="text/javascript" src="windowOnLoad.js"></script>

-----------------------------------------------------------
Example:
<script type="text/javascript" src="windowOnLoad.js"></script>

function functionToLoad() {
	alert("Execute me on page-load, please");
}

addLoadEvent(function(){functionToLoad();});

-----------------------------------------------------------
Dependencies:
None

**********************************************************/

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
            onLoadScripts.push(func);
        }
    }
}


/*********************************************************
Name:
reloadOnLoadScripts script

-----------------------------------------------------------
Description:
Function that enables reloading of the functions loaded
onpageload for AJAX environments

-----------------------------------------------------------
Usage:
Execute reloadOnLoadScripts() after a part of the website
that is dependent on the windowOnLoad-scripts has been
refreshed.

reloadOnLoadScripts()

-----------------------------------------------------------
Dependencies:
This script depends on the windowOnLoad-script to execute

**********************************************************/

var onLoadScripts = new Array();

function reloadOnLoadScripts () {

	for (var i = 0; i < onLoadScripts.length; i++) {
		onLoadScripts[i]();
	}
}

