/*******************************************************************************
*  menuHorSubVer.js : 2009-12-01 : Javascript para menus horizontales y submenus
*  verticales.
* ------------------------------------------------------------------------------
*  Crea los eventos asociados a los elementos del menu horizontal
*
*  Los elementos del menu se identifican mediante id's con el siguiente formato
*
*  Elemento del menú (primer nivel): (nodoMenu_x, x=número de orden de la opción)
*  Menu desplegado: (nodoSubMenu_x, x=número de orden del elemento de primer nivel)
*******************************************************************************/

var nodoactualMenu = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function inicializarMenu(menuId, submenuId) {

    var nodoMenu = document.getElementById(menuId);
    var nodoSubMenu = document.getElementById(submenuId);

    if (nodoMenu == null && nodoSubMenu == null) return;

    nodoMenu.onmouseover = function() {
		if (nodoactualMenu != null) {
			nodoactualMenu.style.visibility = "hidden";
		}
        this.showMenu();		
    }

    nodoMenu.onclick = function() {
		if (nodoactualMenu != null) {
			nodoactualMenu.style.visibility = "hidden";
            nodoactualMenu = null;
		}
        if (nodoSubMenu != null) {
        	this.showMenu();
			return false;
		} else {		
        	return true;
		}
    }

    nodoMenu.showMenu = function() {
	
		if (nodoSubMenu != null) {
        	nodoSubMenu.style.left = this.offsetLeft + "px";
        	nodoSubMenu.style.top = this.offsetTop + this.offsetHeight + "px";
        	nodoSubMenu.style.visibility = "visible";
        	nodoactualMenu = nodoSubMenu;
		}
    }

	if (nodoSubMenu != null) {
	
	    nodoSubMenu.onmouseover = function() {
			nodoSubMenu.style.visibility = "visible";
		}
	    nodoSubMenu.onmouseout = function() {
			nodoSubMenu.style.visibility = "hidden";
			nodoactualMenu = null;
		}
    }
	
}

window.onload = function() {

	var menuId = null;
	var submenuId = null;
		
	// Procesamos todos los nodos del menu	
	for(var cont=1;document.getElementById("nodoMenu_"+cont)!= null; cont++) {
	
		menuId="nodoMenu_"+cont;
		submenuId="nodoSubMenu_"+cont; //Asignamos el nombre del submenu por si tubiera
		if (document.getElementById(submenuId) == null) {		
			inicializarMenu(menuId); 
		} else {
			inicializarMenu(menuId,submenuId);		
		}
	}
		
}