﻿/**
 * Classe qui permet d'executer des commandes dans le onLoad du body
 *
 *@author Nicolas Desy 
 */ 


InitCommand = {}; 
InitCommand._commandQueue = [];

/**
 * Ajoute une commande dans la queue
 * @cmd La commande : soit une fonction ou bien un object avec une methode execute()
 */ 
InitCommand.addCommand = function(cmd){
    if(typeof cmd == "function"){
        InitCommand._commandQueue.push({execute:cmd});
    }else{
        InitCommand._commandQueue.push(cmd);
    }
}

InitCommand.clear = function(){
    InitCommand._commandQueue = [];
}



window.onload = function(){    
    var queue = InitCommand._commandQueue;
    for(var i=0; i<queue.length; i++){       
        queue[i].execute();
    }
}


//TODO :  enlever ca d'ici, je ne sais pas pourquoi c'est la
InitCommand.addCommand(function() {
    
    if (document.all && document.getElementById) {
        var navRoot = document.getElementById("nav");
        for (var i = 0 ; i < navRoot.childNodes.length ; i++) {
            var node = navRoot.childNodes[i];
            
            if (node.nodeName=="LI") {
                node.onmouseenter=function() {
                    this.className += " over";
                }
                node.onmouseleave=function() {
                    this.className = this.className.replace(" over", "");
                }
            }
        }
    }   
});




UnloadCommand = {}; 
UnloadCommand._commandQueue = [];

/**
 * Ajoute une commande dans la queue
 * @cmd La commande : soit une fonction ou bien un object avec une methode execute()
 */ 
UnloadCommand.addCommand = function(cmd){
    if(typeof cmd == "function"){
        UnloadCommand._commandQueue.push({execute:cmd});
    }else{
        UnloadCommand._commandQueue.push(cmd);
    }
    window.onunload = UnloadCommand.onunload;
}



UnloadCommand.onunload = function(){     
    var queue = UnloadCommand._commandQueue;
    for(var i=0; i<queue.length; i++){		
        if(!queue[i].execute()) {
            return false;
        }
    }
    return true;
}