/*
 * menuExpandable2.js - implements an expandable menu based on a HTML list
 * Author: Dave Lindquist (dave@gazingus.org)
 *
 * updated by Rey Echevarria
 */

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;
	
    if (actuator.className == 'single'){
		menu.style.display = 'none';
		actuator.onclick = function(){
			var menu_items = document.getElementsByTagName('menu');
			
			for (var i=0; i<menu_items.length; i++){
				if(menu_items[i].id.search(/_Menu/) != -1){
					menu_items[i].style.display = 'none';
				}
			}
			
			menu.style.display = 'block';
			
			
			//style debugging
			/*menu_items = document.getElementsByTagName('menu');
			for (var i=0; i<menu_items.length; i++){
				alert(menu_items[i].id+" "+menu_items[i].style.display);
			}*/
			
			
			return;
		}
    }
	if (actuator.className == 'multiple'){
		menu.style.display = 'none';
		actuator.onclick = function() {
        	var display = menu.style.display;
        	//menu.parentNode.style.backgroundImage = (display == "block") ? "url()" : "url()";
        	menu.style.display = (display == 'block') ? 'none' : 'block';
        	return;
		}
    }
	if (actuator.className == 'none'){
		menu.style.display = 'none';
		return;
    }
}

function expandMenu(menuId) {
	//alert('show: '+this.className);
	var menu = document.getElementById(menuId);
	if ( menu == null ) return;
	menu.style.display = 'block';
	//currentMenu.parentNode.style.backgroundImage ="url()";
}


/*function showOnlyMenu(menuId){
	if (document.getElementById(menuId) != null){
		var actuatorId = menuId.replace(/_Menu/,'_Actuator');
		//actuatorId = actuatorId.replace(/nav_main_/,'');
		var actuator = document.getElementById(actuatorId);
		// alert('show only: '+actuatorId);
		var menu = document.getElementById(menuId);
		var menu_items = document.getElementsByTagName('menu');
		for (var i=0; i<menu_items.length; i++){
			if(menu_items[i].id.search(/_Menu/) != -1){
				menu_items[i].style.display = 'none';
			}
		}
		menu.style.display = 'block';
	}

	return;
}*/


function showOnlyMenu(menuId, menuId2){
	//if (document.getElementById(menuId2) == null){
		
		if (document.getElementById(menuId) != null){
			var actuatorId = menuId.replace(/_Menu/,'_Actuator');
			//actuatorId = actuatorId.replace(/nav_main_/,'');
			var actuator = document.getElementById(actuatorId);
			// alert('show only: '+actuatorId);
			var menu = document.getElementById(menuId);
			var menu_items = document.getElementsByTagName('menu');
			for (var i=0; i<menu_items.length; i++){
				if(menu_items[i].id.search(/_Menu/) != -1){
					menu_items[i].style.display = 'none';
				}
			}
			menu.style.display = 'block';
			
			if (document.getElementById(menuId2) != null) {
				//var actuatorId2 = menuId2.replace(/_Menu/,'_Actuator');
				//var actuator2 = document.getElementById(actuatorId2);
				var menu2 = document.getElementById(menuId2);
				menu2.style.display = 'block';
			}
			
			var liId = menuId.replace("_Menu","_Tier1");
			var li = document.getElementById(liId);
			var li_items = document.getElementsByTagName('li');
			for (var i=0; i<li_items.length; i++){
				if(li_items[i].id.search(/_Tier1/) != -1){
					li_items[i].style.display = 'none';
				}
			}
			li.style.display = 'block';
			
		}
	//}
	
	/*if (document.getElementById(menuId2) != null) {
		alert("passing menuid2="+document.getElementById(menuId2).id);
		showAllMenus();
	}*/
	return;
}
function showAllMenus(){
	// alert('show all: '+this.className);
	var menu_items = document.getElementsByTagName('menu');
		for (var i=0; i<menu_items.length; i++){
			if(menu_items[i].id.search(/_Menu/) != -1){
				menu_items[i].style.display = 'block';
			}
		}
	return;
}
function hideMenu(menuId) {
	var menu = document.getElementById(menuId);
	if ( menu == null ) return;
	menu.style.display = 'none';
	//currentMenu.parentNode.style.backgroundImage ="url()";
}