// Script to activate and desactivate the menu-items

//Set here how many submenus there will be at maximum
var MAX_SUBMENUS = 10;

function setActiveMenu(){
	var url = window.location.toString();
	var start = url.indexOf("menu_id=")+8;
	var main_id = url.substr(start,1);
	var sub_id = url.substr(start+1,1);
	
	//Unset all elements
	fktMenuUnHover();
	
	//Show active submenu if it exists
	showSubMenu("sub"+main_id);
	
	//Set correct main_item to active
	if(main_id != 0 && document.getElementById("menu_main_item"+main_id) != null)
		document.getElementById("menu_main_item"+main_id).style.listStyleImage = "url(images/iguane-bullet-first_active.jpg)";
	
	//If is set, set correct sub_item to active
	if(sub_id != 0 && document.getElementById("menu_sub_item"+main_id+sub_id) != null)
		document.getElementById("menu_sub_item"+main_id+sub_id).style.listStyleImage = "url(images/iguane-bullet-second_active.jpg)";
}

//Set all menu_items to normal mode, non-active
function fktMenuUnHover(){
	//Get all menu items, including submenu_items
	menu_items = document.getElementById("menu_container").getElementsByTagName("li");
	
	for (var i=0;i<menu_items.length;i++)
		if(menu_items[i].className == "menu_item_first_level")
			menu_items[i].style.listStyleImage = "url(images/iguane-bullet-first.jpg)";
		else if(menu_items[i].className == "menu_item_second_level")
			menu_items[i].style.listStyleImage = "url(images/iguane-bullet-second.jpg)";
}


//Show the corresponding submenu
function showSubMenu(subName){
	hideAllSubMenus();
	
	var el = document.getElementById(subName);
	
	if(el != null){
		el.style.position="relative";
		el.style.visibility="visible";
	}
}


function hideAllSubMenus(){
	var el;
	
	for(var i=1;i<=MAX_SUBMENUS;i++){
		el = document.getElementById("sub"+i);
		if(el != null){
			el.style.position="absolute";
			el.style.visibility="hidden";
		}
	}
}

