var NS=(navigator.appName=='Netscape');
var menucollection=new Array();
var g_oCurrentDrag=null;

function lwFocusLayer(oLayer) {
	document.lw_maxZ++;
	if (NS)
		oLayer.zIndex = document.lw_maxZ;
	else
		oLayer.style.zIndex = document.lw_maxZ;
}

function lwShowLayer(name,toFront) {
	var theLayer;
	if (NS) {
		theLayer = document.layers[name];
		theLayer.visibility = "visible";
	}
	else {
		theLayer = document.all[name];
		theLayer.style.visibility = "visible";
	}
	if( toFront )
		lwFocusLayer(theLayer);
}

function lwHideLayer(name) {
	if (NS)
		document.layers[name].visibility = "hidden";
	else
		document.all[name].style.visibility = "hidden";
}

function lwMoveLayer(oLayer,newLeft,newTop) {
	if (NS)
		document.layers[oLayer].moveTo(newLeft,newTop);
	else {
		document.all[oLayer].style.pixelTop = newTop;
		document.all[oLayer].style.pixelLeft = newLeft;
	}
}

function menu(IDnr,lintTopMenyID,LinkUrl,vcharRubrik,intOrdning,vcharTypKod){
	this.ID=IDnr;
	this.MenyID=lintTopMenyID;
	this.Url=LinkUrl;
	this.Header=vcharRubrik;
	this.Order=intOrdning;
	this.TypKod=vcharTypKod;
}

function showmenu(id){
	window.scroll(0,0);
	for(var i=0;i<menucollection.length;i++){
		if(menucollection[i].MenyID==id){
			lwShowLayer('ID' + menucollection[i].ID,true);
			if(NS){
				lwShowLayer('ID' + menucollection[i].ID+'trans',true);
			}
		}
	}
	if(NS){
		lwShowLayer('vit',false);
		if(document.layers['searchinput']!=null) {
			lwHideLayer('searchinput');
			lwShowLayer('searchpicture',false);
		}
	}
}

function showblue(id){
	for(var i=0;i<menucollection.length;i++){
		lwHideLayer('ID'+menucollection[i].ID+'h');
		if(NS){
			lwHideLayer('ID'+menucollection[i].ID+'bbtrans');
		}
	}
	if (NS){
		if((document.layers['ID'+id].left!=0)&&(document.layers['ID'+id].top>-1)){
			lwMoveLayer('ID'+id+'bb',document.layers['ID'+id].left,document.layers['ID'+id].top);
			lwMoveLayer('ID'+id+'bbtrans',document.layers['ID'+id].left,document.layers['ID'+id].top);
		}
	}else {
		if((document.all['ID'+id].style.pixelLeft!=0)&&(document.all['ID'+id].style.pixelTop>-1)){
			lwMoveLayer('ID'+id+'h',document.all['ID'+id].style.pixelLeft,document.all['ID'+id].style.pixelTop);
		}
	}
	lwShowLayer('ID'+id+'h',true);
	if(NS){
		lwShowLayer('ID'+id+'bbtrans',true);
	}
}

function clearmenu(id){
	for(var i=0;i<menucollection.length;i++){
		if(id!=menucollection[i].MenyID){
			lwHideLayer('ID'+menucollection[i].ID);
			lwHideLayer('ID'+menucollection[i].ID+'h');
			if(NS){
				lwHideLayer('ID'+menucollection[i].ID+'trans');
				lwHideLayer('ID'+menucollection[i].ID+'bbtrans');
			}
		}
	}
	if(NS){
		lwHideLayer('vit');
		if(document.layers['searchinput']!=null) {
			lwShowLayer('searchinput',true);
			lwHideLayer('searchpicture');
		}
	}
}

function gotourl(id){
	for(var i=0;i<menucollection.length;i++){
		if(id==menucollection[i].ID){
			if(menucollection[i].TypKod=="E"){
				window.open(menucollection[i].Url,null);
			}else{
				document.location.href=menucollection[i].Url;
			}
		}
	}
}

function showsubmenu(id,posleft,postop,step){
	for(var i=0,MenyID=0;i<menucollection.length;i++){
		if(menucollection[i].ID==id){
			if (NS){
				if((document.layers['ID'+id].top!=0)&&(document.layers['ID'+id].top)){
					postop=document.layers['ID'+id].top;
//					alert("HIT"+postop);
				}
				//document.layers['ID'+id].moveTo(posleft,postop);
			}else {
				if((document.all['ID'+id].style.pixelLeft!=0)&&(document.all['ID'+id].style.pixelTop)){
					postop=document.all['ID'+id].style.pixelTop;
				}
			}
			//alert(menucollection[i].Header);
			MenyID=menucollection[i].MenyID;
			//if((menucollection[i].MenyID==MenyID)){//
			if(MenyID>1){
				for(var j=0;j<menucollection.length;j++){
					if(menucollection[j].MenyID==MenyID){
						for(var k=0;k<menucollection.length;k++){
							if(menucollection[k].MenyID==menucollection[j].ID){ //Removes the next level menu on the other menu alternatives.
//								for(var l=0;l<menucollection.length;l++){
//									if(menucollection[l].MenyID==menucollection[k].ID){ //Removes the 3rd level menu when hover on 1st.
//										lwHideLayer('ID'+menucollection[l].ID);
//										lwHideLayer('ID'+menucollection[l].ID+'bb');
//										if(NS){
//											lwHideLayer('ID'+menucollection[l].ID+'trans');
//											lwHideLayer('ID'+menucollection[l].ID+'bbtrans');
//										}
//									}
//								}
								lwHideLayer('ID'+menucollection[k].ID);
								lwHideLayer('ID'+menucollection[k].ID+'bb');
								if(NS){
									lwHideLayer('ID'+menucollection[k].ID+'trans');
									lwHideLayer('ID'+menucollection[k].ID+'bbtrans');
								}
							}
						}
					}
				}
	//			MenyID=0;
			}
		}
	}	
	for(var i=0;i<menucollection.length;i++){
		if(menucollection[i].MenyID==id){
			lwMoveLayer('ID' + menucollection[i].ID,posleft,postop);
			lwShowLayer('ID' + menucollection[i].ID,true);
			if(NS){
				lwMoveLayer('ID' + menucollection[i].ID+'trans',posleft,postop);
				lwShowLayer('ID' + menucollection[i].ID+'trans',true);
			}
			postop=postop+step;
		}
	}
}


