/**
 * ON LOAD HANDLER (Futurniture 2006)
 * 
 */
var onLoadFunctions = new Array();

/**
 * Adds a function to be executed when the page is loaded
 * @param funcAsString The function to be executed, as a string (ie "func()")
 * @param executeOnDOMLoad Should the function be executed when the DOM (true) or when the page (false) is loaded 
 */
function appendOnLoadFunction(funcAsString, executeOnDOMLoad) {
     onLoadFunctions.push(new LoadFunction(funcAsString, executeOnDOMLoad));
}

/**
 * LoadFunction
 * A Load Function instance
 * @param funcAsString The function to be executed, as a string (ie "func()")
 * @param executeOnDOMLoad Should the function be executed when the DOM (true) or when the page (false) is loaded 
 */
function LoadFunction(funcAsString, executeOnDOMLoad) {
    this.funcAsString = funcAsString;
    this.executeOnDOMLoad = executeOnDOMLoad;
}

LoadFunction.prototype.execute = function() {
    this.isExecuted = true;
    eval(this.funcAsString);
}

function onDOMLoadEventHandler() {
    for (var i = 0; i < onLoadFunctions.length; i++) {
        if (onLoadFunctions[i].executeOnDOMLoad) {
            onLoadFunctions[i].execute();
        }
    }
}

function onPageLoadEventHandler() {
    for (var i = 0; i < onLoadFunctions.length; i++) {
        if (!onLoadFunctions[i].isExecuted) {
            onLoadFunctions[i].execute();
        }
    }
}

// for Mozilla
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", onDOMLoadEventHandler, false);
}
window.onload = onPageLoadEventHandler;

function debug(str) {
    document.getElementById("debug").innerHTML += str + "<br/>";
}

