var menuWidth = 138;
//change this value to set the delay for menu 
var delayShowLevel = 0;
function findXpos(objElement){
	
	var curleft = 0;
	objX = objElement;
	if (objX.offsetParent)
	{
		while (objX.offsetParent)
		{
			curleft += objX.offsetLeft
			objX = objX.offsetParent;
		}
	}
	else if (objX.x)
		curleft += objX.x;
		
	return curleft + menuWidth;
}


var delayTimer, oUlChild;
arrObjUlChilds = new Array();
function showLevel(oParent){
	
	//Hide the submenu if it is visible
	if(oUlChild != null){
		
		var arrPos;
		if(oParent.parentNode.parentNode.className == "firstLevel")
			hideAllLelvels();
		
		for(var i=0; i < arrObjUlChilds.length; i++){
			if(arrObjUlChilds[i] == oParent.parentNode.parentNode){
				arrPos = i;
			
			}
			
			//Hide the level if it's not the same as parent child and clear the array  
			if(i > arrPos && arrPos != null){
				arrObjUlChilds[i].parentNode.style.zIndex = 2;
				arrObjUlChilds[i].style.visibility = "hidden";
				arrObjUlChilds[i][i].className = "notSelected";
			}
		}
	}
	

	/*
		Getting the child (submenu) to show.
		Set the positions before making child visible
	*/
	var oChildren = oParent.parentNode.childNodes;
	
	for (var i=0; i < oChildren.length; i++) {
		if(oChildren[i].nodeName == "UL"){
			oUlChild = oChildren[i];
			break;
		}
		else{
			oUlChild = "noChild";
		}
	}
	/*
		Put the child in array so that we know wich childs are visible
	*/
	if(oUlChild != null){
		var levelName = oUlChild.className;
		if(oUlChild != "noChild"){
			var level = levelName.substring(5, levelName.length)
			arrObjUlChilds[level] = oUlChild;
			arrObjUlChilds[level][level] = oParent;
		}
	}
	
	/*
		Run pause script before making sublevel visible
	*/
	if(delayTimer != null)
		clearTimeout(delayTimer);
	

	if(oUlChild != null && oUlChild != "noChild"){
		// Hide Iframes for ie5 when menu is active
		if(is.ie5){
			hideIFrames("hidden");
		}
		
		//hideSelectElements("hidden");
		
		//oParent.className = "selected";
		oUlChild.parentNode.style.zIndex = 200;
		oUlChild.style.left = "0px";
	
		//check if the submenu is in view
		var xWidth;
		if (self.innerHeight){
			xWidth = self.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientHeight){
			xWidth = document.documentElement.clientWidth;
		}
		else if (document.body){
			xWidth = document.body.clientWidth;
		}
		
		if(xWidth < findXpos(oUlChild) && oUlChild.className != "level0" ){
			oUlChild.style.left = "-370px";
		}
		// Show sublevel
		delayTimer = setTimeout("oUlChild.style.visibility = 'visible'", delayShowLevel);
	}
}

function hideMenuIfNotActive(){
	
		if(delayTimer != null)
			clearTimeout(delayTimer);
		
		delayTimer = setTimeout("hideAllLelvels()",1000);
}

function hideAllLelvels(){
	if(is.ie5){
		hideIFrames("visible");
	}
	//hideSelectElements("visible")
	for(var y = 0; y < arrObjUlChilds.length; y++){
		if(arrObjUlChilds[y] != null){
			arrObjUlChilds[y].parentNode.style.zIndex = 2;
			arrObjUlChilds[y].style.visibility = "hidden";
			//arrObjUlChilds[y][y].className = "notSelected";
		}
		
	}
}


function CreateNPTopMenu() {
	if (!document.getElementsByTagName || !document.getElementById("site-menu")) return false;
	var a = document.getElementById("site-menu").getElementsByTagName("a");
	for (var i=0; i < a.length; i++) {
		a[i].onmouseover = function() {
			showLevel(this);
			return false;
		}
		a[i].onmouseout = function() {
			hideMenuIfNotActive();
			return false;
		}
	}
	
	document.onclick = function(){
		hideAllLelvels();
	}
}
/* 
	End menu
*/	
	
//Add CreateNPTopMenu function to Window.Load array
//SafeAddOnload(CreateNPTopMenu());	

//*********************************************
// Changes the style of tree menu node
//
// parameters:
// - source:	presents the "img" element
//*********************************************
function LeftNodeOver(elm) {
	elm.setAttribute("oldClassName", elm.className);
	if(elm.className != "selectedTreeNode" && elm.className != "hasTreeNodeChildrenAndSelected"){
		elm.className = "treeNodeHover";
	} else {
		elm.className = "treeSelectedNodeHover";
	}
}

//*********************************************
// Changes the style of tree menu node
//
// parameters:
// - source:	presents the "img" element
//*********************************************
function LeftNodeOut(elm) {
	var oldClassName = elm.getAttribute("oldClassName");
	if(oldClassName != null) {
		elm.className = oldClassName;
	}
}

//*********************************************
// Shows or hides the menu level on mouse click
//
// parameters:
// - source:	presents the "img" element
//*********************************************
function LeftMenuClick(source) {
	//this parameter presents the "tree icon"
	var liChildren = source.parentNode.childNodes;
	//check the last child of "li" container
	//and if it is UL element, change its display style
	if (liChildren.length > 0) {
		//var ulIndex = liChildren.length - 1;
		//var ulElm = liChildren[ulIndex];
		//alert('mladen1' + ulElm.nodeName);
		var ulElm = liChildren[liChildren.length - 1];
		if (ulElm.nodeName == "UL") {
			if(source.className == "iconCollapsed") {
				source.className = "iconExpanded"
				source.src = strImgExpanded;
				ulElm.style.display = "block";
			} else if (source.className == "iconExpanded"){
				source.className = "iconCollapsed"
				source.src = strImgCollapsed;
				ulElm.style.display = "none";
			} else if (source.className == "iconSubCollapsed") {
				source.className = "iconSubExpanded";
				source.src = strSubImgExpanded;
				ulElm.style.display = "block";
			} else if (source.className == "iconSubExpanded") {
				source.className = "iconSubCollapsed";
				source.src = strSubImgCollapsed;
				ulElm.style.display = "none";
			}
		}
	}
}