function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
}


is = new BrowserCheck();





var arrMenu = new Array();




function menuItem(nid, pnid, strName, strLink, strURL)
{
	this.nid = nid;
	this.pnid= pnid;
	this.strName = strName;
	this.strLink = strLink;
	this.strURL = strURL;
	this.created = false;
	this.isSelected = false;
	this.hasChildren = false;
}

function addItem(nid, pnid, strName, strLink, strURL)
{
	if(arrMenu[pnid])
	{
		arrMenu[pnid].hasChildren = true;
	}
	arrMenu[nid] = new menuItem(nid, pnid, strName, strLink, strURL);
}


function getPath (CAR_ID, strDelimiter)
{
	var strPath = ""
	while(arrCars[CAR_ID])
	{
		strPath = arrCars[CAR_ID].strName + strDelimiter + strPath;
		CAR_ID = arrCars[CAR_ID].intParent;
	}
	
	return strPath;
}

	
function LoadMenu()
{
	objMenu = document.getElementById("menuObject");
	objNode = objMenu.firstChild;
	while(objNode)
	{		
		if(objNode.nodeName=="A")
		{
			strURL = objNode.href;
			
			strName = objNode.innerHTML;
			
			tmp_nid = objNode.getAttribute("nid");
			tmp_pnid = objNode.getAttribute("pnid");
			
			addItem(tmp_nid, tmp_pnid, strName, tmp_nid + ".aspx", strURL);
		}
		objNode = objNode.nextSibling;
	}
}


		hideTimeout = null;
		hideTimeout2 = null;
		currentNid = null
		
		function objOver(nid)
		{
			hidePopups(nid);
			
			
			if (hideTimeout2 != null)
			{
				clearTimeout(hideTimeout2);
				hideTimeout2 = false;
			}
			
			hideTimeout2 = setTimeout("objCreate('"+nid+"')", 300);
			
		}	
		
		function objCreate(nid)
		{
			
			// Kontrollera om det finns några childs..
			exists  = false;
			for(key in arrMenu)
			{
				if (arrMenu[key].pnid == nid)
				{
					exists = true;
				}
			}
			if(exists == false) return;
			
			tdObj = document.getElementById("t" + nid);

			//kontrollera om div'en existerar, annars skapa en..
			divObj = document.getElementById("d" + nid);
				
			if (divObj == null)
			{
				divObj = document.createElement("div");
				divObj.setAttribute("id", "d" + nid);
				divObj.setAttribute("nid",nid);
				divObj.onmouseover = divOver;
				divObj.onmouseout = divOut;
				
				// Style
				divObj.style.position = "absolute";
				divObj.style.visibility = "hidden";
				divObj.style.top = "0px";
				divObj.style.left = "0px";
				
				
				if(is.ie)
				{			
					var iFrame;
					iFrame = "<iframe id=\"iFrameID"+ nid +"\" scrolling=\"no\" frameborder=\"0\"></iframe>";
					document.body.insertAdjacentHTML("beforeEnd", iFrame);	
				}
					
				// Skapa tabellen
				strHtml = "";
				strHtml += "<div></div><div><table class=menuSub cellpadding=2 border=0 cellspacing=0>";
				
				for( key in arrMenu)
				{	
					if(arrMenu[key].pnid == nid)
					{
						strHtml += "<tr><td class=menuItem id=\"t"+ arrMenu[key].nid +"\" onMouseOver=\"objOver('"+ arrMenu[key].nid +"')\" onClick=\"objClick('"+ key +"');\">"+ arrMenu[key].strName +"</td></tr>";
					}
				}
				
				strHtml += "</table></div><div></div>";
				divObj.innerHTML = strHtml;
				document.body.appendChild(divObj);
				arrMenu[nid].created = true;
			}
			
			
			cWidth = document.body.clientWidth;
			cHeight = document.body.clientHeight;
			sTop = document.body.scrollTop;
			
			//window.status = sTop;
			
			menuHeight = divObj.clientHeight;
			
			
			// Kontrollera om det är ett root objekt
			
			objNode = document.getElementById("a" + nid);
			tmp_pnid = objNode.getAttribute("pnid");
			
			if(tmp_pnid == 0)
			{
				// Root
				x = getAbsoluteLeft(tdObj);
				y = getAbsoluteBottom(tdObj);
				if( y + menuHeight > cHeight )
				{
					y = sTop;
				}
			}
			else
			{
				menuY = getAbsoluteTop(tdObj);
			
				x = getAbsoluteRight(tdObj);
				y = getAbsoluteTop(tdObj);
				y1 = getAbsoluteBottom(tdObj);
				
				if(menuHeight > cHeight)
				{
					y = sTop;
					window.status = "Topped.. menuHeight:" + menuHeight + ", cHeight:" + cHeight;
				}
				else if( y + menuHeight > cHeight)
				{
					yDiff = y + menuHeight - cHeight;
					y = y - yDiff;
					//window.status = "Changed..";
				}
			}
			
			
			divObj.style.left = x + "px";
			divObj.style.top = y + "px";
			
			divObj.style.zIndex = 1000;
			setTimeout("divObj.style.visibility = \"visible\"",50);
			
			
			
			if(is.ie)
			{
				iFrame = document.getElementById("iFrameID" + nid);
			
				iFrame.style.zIndex 	= 100;
				iFrame.style.position	= "absolute";
				iFrame.style.top 		= y + "px";
				iFrame.style.left 		= x + "px";
					
				iFrame.height = divObj.clientHeight;
				iFrame.width = divObj.clientWidth;
			}
		}
		
		
		
		function objClick(nid)
		{
			if(arrMenu[nid].hasChildren == false)
			{
				hidePopups(null);
				
				nid = nid.replace("/","X");
				document.location.href = nid + ".aspx";
			}
		}
		
		
		
		function divOver()
		{
			nid = this.nid;
			
			if (hideTimeout != null)
			{
				clearTimeout(hideTimeout);
				hideTimeout = false;
			}	
		}
		
		function divOut()
		{
			nid = this.nid;
			hideTimeout = setTimeout("hidePopups(null)", 300);
		}
		
		function hidePopups(nid)
		{
			for( key in arrMenu)
			{	
				if(arrMenu[key].created == true)
				{
					divObj = document.getElementById("d" + key)
					
					if(divObj)
					{
						divObj.style.visibility = "hidden";
						if(is.ie)
						{
							var iFrame = document.getElementById("iFrameID" + key);
							iFrame.style.visibility = "hidden";
						}
					}
				}
				
				if(arrMenu[key].isSelected == true)
				{
					tdObj = document.getElementById("t" + key);
					if(tdObj)
					{
						tdObj.className = "menuItem";
					}
				}
			}
		
			if(nid)
			{
				objNode = document.getElementById("a" + nid);
			
				while(objNode)
				{
					tmp_pnid = objNode.getAttribute("pnid");
					tmp_nid = objNode.getAttribute("nid");
					
					menuItem = document.getElementById("t" + tmp_nid);
					menuItem.className = "menuItemOver";
					arrMenu[tmp_nid].isSelected = true;
					
					divObj = document.getElementById("d" + tmp_nid);
					if(divObj)
					{
						divObj.style.visibility = "visible";
					}
					
					if(is.ie)
					{
						var iFrame = document.getElementById("iFrameID" + tmp_nid);
						if(iFrame)
							iFrame.style.visibility = "visible";
					}
						
					objNode = document.getElementById("a" + tmp_pnid);
				}	
			}
			
		
		}
		
		function getAbsoluteLeft(o) {                                                        
		// Get an object left position from the upper left viewport corner                      
		// Tested with relative and nested objects                                              
		
		oLeft = o.offsetLeft           // Get left position from the parent object             
		while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent    // Get parent object reference                          
			oLeft += oParent.offsetLeft  // Add parent left position                             
			o = oParent                                                                         
		}                                                                                       
		// Return left postion                                                                  
		return oLeft                                                                            
	}                                                                                
	
	function getAbsoluteRight(o) {                                                        
		// Get an object left position from the upper left viewport corner                      
		// Tested with relative and nested objects                                              
		
		oRight = o.offsetLeft + o.offsetWidth;           // Get left position from the parent object             
		
		while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent // Get parent object reference                          
			
			oRight += oParent.offsetLeft  // Add parent left position                             
			o = oParent                                                                         
		}                                                                                       
		// Return left postion                                                                  
		
		return oRight                                                                            
	}                                                                                
	            
	            
	            
	function getAbsoluteBottom(o) {                                                        
		// Get an object left position from the upper left viewport corner                      
		// Tested with relative and nested objects                                              
		
		oBottom = o.offsetTop + o.offsetHeight; // Get left position from the parent object             
		
		while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent    // Get parent object reference                          
			
			oBottom += oParent.offsetTop // Add parent left position                             
			o = oParent                                                                         
		}                                                                                       
		// Return left postion                                                                  
		return oBottom                                                       
	}                                                                                          
	
	function getAbsoluteTop(o) {
		// Get an object left position from the upper left viewport corner                      
		// Tested with relative and nested objects                                              
		
		oTop = o.offsetTop; // Get left position from the parent object             
		while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent    // Get parent object reference                          
			oTop += oParent.offsetTop // Add parent left position                             
			o = oParent                                                                         
		}                                                                                       
		// Return left postion                                                                  
		
		return oTop
	} 
	
	
	
	
	
	
	
