function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

var offsetxpoint=-28; //Customize x offset of menu
var offsetxpointchild=-15; 
var offsetypoint=18; //Customize y offset of menu

function hideMe(obj){
    var tmpObj=document.getElementById(obj)
    tmpObj.style.visibility='hidden';
    if(tmpObj.parentNode.childNodes[0] && tmpObj.parentNode.childNodes[0].className=='parentChildOut'){
		tmpObj.parentNode.childNodes[0].className='parent';
		if(document.all){
			document.getElementById('divShim').style.display='none';
		}
	}
	else{
		tmpObj.parentNode.childNodes[0].className='menuRow';
		if(document.getElementById('divShimChild')){
			if(document.all && tmpObj.offsetLeft==document.getElementById('divShimChild').offsetLeft){
				document.getElementById('divShimChild').style.display='none';
			}
		}	
	}
}

function fixSelectBox(cBool, yy, xx, h, w, z){
	if(document.all){
		if (document.getElementById('divShimChild')){
			var IfrRefPos = document.getElementById('divShimChild');
			var IfrRef = cBool?document.getElementById('divShim'):document.getElementById('divShimChild');
			IfrRef.style.width = w;
			IfrRef.style.height = h;
			IfrRef.style.top = cBool?yy+IfrRefPos.offsetTop:yy;
			IfrRef.style.left = cBool?xx+IfrRefPos.offsetLeft:xx;
			IfrRef.style.zIndex = z;
			IfrRef.style.display = "block";
		}
	}	
}

var wrapperWidth=0;
var posMenuRow=0;
function setExpandFunction(obj){
	//Loop all the menu-items to correctly display them.
	var intLoop=0;
	
	intLoop = obj.childNodes.length-1;
	for(var i=0;i<=intLoop;i++){  
		if(obj.childNodes[i].childNodes.length > 1) {
 //           if(obj.childNodes[i].childNodes[0].className!='menuRow') {
    			if(obj.childNodes[i].childNodes[0].tagName=='A'){
    				
    				obj.childNodes[i].childNodes[0].timer=null;
    				//this.src = (display == "block") ? document.images.imgPlus.src : document.images.imgMinus.src;
    				for (var j = 0; j < obj.childNodes[i].childNodes[0].parentNode.childNodes.length; j++) {
    					if (obj.childNodes[i].childNodes[0].parentNode.childNodes[j].tagName.toUpperCase() == "UL") {		
                            obj.childNodes[i].childNodes[0].showObj=obj.childNodes[i].childNodes[0].parentNode.childNodes[j];
                			                            
                            if(obj.childNodes[i].childNodes[0].className!="menuRow") {
                    			//Events
                    			
                                obj.childNodes[i].childNodes[0].className='parent';
                                obj.childNodes[i].childNodes[0].parentNode.childNodes[j].style.left=posMenuRow+194<wrapperWidth? obj.childNodes[i].childNodes[0].offsetWidth+offsetxpointchild+"px":obj.childNodes[i].childNodes[0].offsetLeft+offsetxpointchild-196+"px"
                    			obj.childNodes[i].childNodes[0].parentNode.childNodes[j].style.top= obj.childNodes[i].childNodes[0].offsetTop-1+"px"
                    			obj.childNodes[i].childNodes[0].onmouseover = function() {
                    				clearTimeout(this.timer);
                    				this.showObj.style.visibility = "visible";
                    				this.className='parentChildOut';
                    				fixSelectBox(true,this.offsetTop-1,this.showObj.offsetLeft,this.showObj.offsetHeight,this.showObj.offsetWidth, this.showObj.style.zIndex-1);
                    			}
                            }
                            else {
                                posMenuRow=obj.childNodes[i].childNodes[0].offsetLeft+194;
                                insWrapper=wrapperWidth-posMenuRow
                                obj.childNodes[i].childNodes[0].parentNode.childNodes[j].style.left=posMenuRow<wrapperWidth?obj.childNodes[i].childNodes[0].offsetLeft+offsetxpoint+"px":obj.childNodes[i].childNodes[0].offsetLeft+offsetxpoint-5+insWrapper+"px";
                                obj.childNodes[i].childNodes[0].parentNode.childNodes[j].style.top=offsetypoint+"px"
                                
                                obj.childNodes[i].childNodes[0].onmouseover = function() {
                    				clearTimeout(this.timer);
                    				this.showObj.style.visibility = "visible";
                    				this.className='menuRowChildOut';
                    				fixSelectBox(false,this.showObj.offsetTop,this.showObj.offsetLeft,this.showObj.offsetHeight,this.showObj.offsetWidth, this.showObj.style.zIndex-1);
                    			}
                                /*obj.childNodes[i].childNodes[0].onmouseover = function() {
                    				clearTimeout(this.timer);
                    			}*/
                    			
                    			// WGS SPECIAL... Menyn (location) ballar ur om man pekar mot en annan mapp i trädet
    							// T.e.x: Om man skall till kassan, så skriver vi i managern ../kassa/kassa_xml.asp
    							// När man sedan trycker på länken ärver alla andra länkar i menyn '/kassa/'-mappen
    							// Vi får då följande ex) docs/kassa/search.asp skall vara docs/webshop/search.asp
    							// Detta är ingen snygg lösning, men den funkar för kassa_xml länken.
    							// Någon klyftig person får jobba vidare på någon bättre lösning.
    							// KRRO ( 20/7 dagen innan proddning/release av ny site)
			    				
    							//if(obj.childNodes[i].childNodes[0].className="menuRow") {
    							//	var location = obj.childNodes[i].childNodes[0].href;
    							//	location = location.toUpperCase();
    							//	if(	location.indexOf("/KASSA/") != -1 && location.indexOf("KASSA_XML") == -1 ){
    							//		//alert(location);
    							//		arraySplit = location.split("/KASSA/");
    							//		newLocation = arraySplit[0] + "/WEBSHOP/" + arraySplit[1];
    							//		newLocation = newLocation.toLowerCase();
    							//		//alert(newLocation);
    							//		obj.childNodes[i].childNodes[0].href = newLocation;
    							//	}
    							//}
			    				
    							// SLUT WGS SPECIAL
    							//
                    			
                            }
                            
                            //DÖLJ
                            obj.childNodes[i].childNodes[0].onmouseout = function() {
                				clearTimeout(this.timer);
                				this.timer=setTimeout("hideMe('"+this.showObj.id+"')",200);
                			}
                			obj.childNodes[i].childNodes[0].parentNode.childNodes[j].showObj=obj.childNodes[i].childNodes[0];
                			obj.childNodes[i].childNodes[0].parentNode.childNodes[j].onmouseover=function(){clearTimeout(this.showObj.timer);}
                			obj.childNodes[i].childNodes[0].parentNode.childNodes[j].onmouseout=function(){
                					clearTimeout(this.showObj.timer);
                					this.showObj.timer=setTimeout("hideMe('"+this.id+"')",200);
                            }
                			//end events
    					}
   // 				}
                }
			}
			for (var j = 0; j < obj.childNodes[i].childNodes.length; j++) {
				if (obj.childNodes[i].childNodes[j].tagName == "UL" || obj.childNodes[i].childNodes[j].tagName == "ul") {
					setExpandFunction(obj.childNodes[i].childNodes[j]); //Anropa sig självt
				}
			}
		}
	}
}
	
function initializeMenu(menuID){
	var menu = document.getElementById(menuID);
	wrapperWidth=document.getElementById('mainMenu').offsetWidth;
	if (menu) {
		setExpandFunction(menu.childNodes[0]); //Starta anropet till rekursiva funktionen.
		menu.childNodes[0].style.display = "block";
		menu.childNodes[0].style.visibility = "visible"; //Visa menyn
	}
}

