var IE5 = false, Loaded = false, LagStreng = "", HtmlStreng  = "", nnWidth = 0, nnHeight = 0, tal = 0;


if(navigator.userAgent.indexOf("MSIE") == -1)
{
	if (document.getElementById)
		NS6 = true;
	else
		NS4 = true;
     nnWidth = window.innerWidth, nHeight = window.innerHeight;
     window.onResize = reloadMenu;
}
else
	if (parseInt(navigator.appVersion.substring(navigator.appVersion.indexOf('MSIE')+5,navigator.appVersion.length))>=5)
		IE5 = true;

var IE4 = document.all;
var NS4 = document.layers;
var NS6 = document.getElementById;
//if (IE4) document.write('IE4<br>');
//if (IE5) document.write('IE5<br>');
//if (NS4) document.write('NS4<br>');
//if (NS6) document.write('NS6<br>');

function Init(){
	var i, j, p;
	for ( i = 0; i <= (HovedMenu.length - 1); i++)
	{
		p = eval(HovedMenu[i][0]);
		if (p.length > 0)
		{
			HtmlStreng = "<TABLE BORDER = " + MenuRammeTyk + " CELLSPACING = 0 CELLPADDING = 0 BGCOLOR = " + MenuBaggrund + ">";
			for (j = 0; j <= (p.length - 1); j++)
//				if ((NS4 || NS6) && !IE4 && !IE5)
//					HtmlStreng += "<TR><TD><a href=" + p[j][0] + " style=text-decoration:none>" + UnderMenuTekst + "&nbsp;" + p[j][1] + "&nbsp;" + "&nbsp;</A></TD></TR>"
//				else if (IE4 || IE5)
//				{
//					if (IE5)
//						HtmlStreng += "<TR><TD id=pp" + j + i + " onmouseover=SkiftMenuBaggrundIE5('" + MenuHighlightFarve + "','pp" + j + i + "') onmouseout=SkiftMenuBaggrundIE5('" + MenuBaggrund + "','pp" + j + i + "')><NOBR><a href=" + p[j][0] + " style=\"width: 100%\" onFocus=\"this.blur()\">" + UnderMenuTekst + "&nbsp;" + p[j][1] + "&nbsp;</A><image HEIGHT=0 WIDTH=0></TD></TR>"
//					else
//						HtmlStreng += "<TR><TD                    onmouseover=SkiftMenuBaggrund(" + j + "," + i + ")> <nobr><a href=" + p[j][0] + " style=\"width: 100%\" onFocus=\"this.blur()\">" + UnderMenuTekst + "&nbsp;" + p[j][1] + "&nbsp;</A><image HEIGHT=0 WIDTH=0></TD></TR>"
//				}
				if ((NS4 || NS6) && !IE4 && !IE5)
					HtmlStreng += "<TR><TD><a href=" + p[j][0] + " style=text-decoration:none>" + UnderMenuTekst + "&nbsp;" + p[j][1] + "&nbsp;" + "&nbsp;</A></TD></TR>"
				else if (IE4 || IE5)
				{
					if (IE5)
						HtmlStreng += "<TR><TD id=pp" + j + i + " onmouseover=SkiftMenuBaggrundIE5('" + MenuHighlightFarve + "','pp" + j + i + "') onmouseout=SkiftMenuBaggrundIE5('" + MenuBaggrund + "','pp" + j + i + "')><NOBR><a href=" + p[j][0] + " style=\"width: 100%\" onFocus=\"this.blur()\">" + UnderMenuTekst + "&nbsp;" + p[j][1] + "&nbsp;</A><image HEIGHT=0 WIDTH=0></TD></TR>"
					else
						HtmlStreng += "<TR><TD                    onmouseover=SkiftMenuBaggrund(" + j + "," + i + ")> <nobr><a href=" + p[j][0] + " style=\"" + UnderMenuStyle + "\" onFocus=\"this.blur()\">" + UnderMenuTekst + "&nbsp;" + "p[j][1]" + "&nbsp;</A><image HEIGHT=0 WIDTH=0></TD></TR>"
				}
			HtmlStreng += "</TABLE>"
			if (NS4)
			{
					
					LagStreng  = "<LAYER id=" + HovedMenu[i][1] + " onmouseover=showObject(" + i + ") onmouseout=hideObject(" + i + ") style='position:absolute'>";
					Lag = eval("document." + HovedMenu[i][0]);
					document.layers[HovedMenu[i][1]] = new Layer(300,Lag);
					document.layers[HovedMenu[i][1]].top += 10;
					document.layers[HovedMenu[i][1]].visibility = "hide";
					document.layers[HovedMenu[i][1]].zIndex = 3;

					with (document.layers[HovedMenu[i][1]].document)
					prompt("document." + HovedMenu[i][0]);
					{
			      		open();
			      		write(LagStreng + HtmlStreng + "</LAYER>");
			      		close();
			    		}

			}
			else if (NS6 && !IE4 && !IE5)
			{
					var el;
					el = document.getElementById(HovedMenu[i][1]);
					el.innerHTML = HtmlStreng;
					el.style.visibility = 'hidden';
			}
			else if (IE4)
			{
				if (IE5)
					LagStreng  = "<DIV id=" + HovedMenu[i][1] + " onmouseover=showObject(" + i + ") onmouseout=hideObject(" + i + ") style=position:absolute;visibility:visible;z-index:2>";
				else
					LagStreng  = "<DIV id=" + HovedMenu[i][1] + " onmouseover=showObject(" + i + ") onmouseout=hideObject(" + i + ") style=position:absolute;visibility:visible;z-index:2>";
				document.all[HovedMenu[i][0]].insertAdjacentHTML("AfterEnd", LagStreng + "</DIV>");
				document.all[HovedMenu[i][1]].innerHTML = HtmlStreng + "<image HEIGHT=0 WIDTH=0>";

				eval("document.all['" + HovedMenu[i][1] + "'].style.visibility = 'hidden'");
			}
		}
		Loaded = true;
	}
}
function showObject(lagnavn){
	if (HovedMenu[lagnavn][1] != "")
	{
		if (NS4)
			eval("document.layers." + HovedMenu[lagnavn][0] + ".document.layers[0].visibility = 'show'")
		else if (NS6)
		{
			document.getElementById(HovedMenu[lagnavn][1]).style.visibility = 'visible';

			if (lagnavn == 0 && document.getElementById("iframeScroller"))
			{				
				document.getElementById("iframeScroller").style.visibility = "hidden";
				document.getElementById("iframeTemp").style.visibility = "hidden";
			}
		}
		else if (!NS4 && !NS6)
		{
			if (IE5)
				showTopFarve(lagnavn);
			eval("document.all['" + HovedMenu[lagnavn][1] + "'].style.visibility = 'visible'");

			if (lagnavn == 0 && IE5)
			{
				document.getElementById("iframeScroller").style.visibility = "hidden";
				document.getElementById("iframeTemp").style.visibility = "hidden";
			}
			else if (IE4 && lagnavn == 0)
			{
//				document.all("iframeScroller").style.visibility = "hidden";
//				document.all("iframeTemp").style.visibility = "hidden";
			}
		}
	}
}


function hideObject(lagnavn){
	if (HovedMenu[lagnavn][1] != "")
	{
		if (NS4)
			eval("document.layers." + HovedMenu[lagnavn][0] + ".document.layers[0].visibility = 'hide'")
		else if (NS6)
		{
			document.getElementById(HovedMenu[lagnavn][1]).style.visibility = 'hidden';
			
			if (document.getElementById("iframeScroller"))
			{
				document.getElementById("iframeScroller").style.visibility = "visible";
				document.getElementById("iframeTemp").style.visibility = "visible";
			}
			
		}
		else if (!NS4 && !NS6)
		{
			if (IE5)
				hideTopFarve(lagnavn);
			eval("document.all['" + HovedMenu[lagnavn][1] + "'].style.visibility = 'hidden'");
			if (IE5)
			{
				document.getElementById("iframeScroller").style.visibility = "visible";
				document.getElementById("iframeTemp").style.visibility = "visible";

			}
//			else if (IE4)
//			{
//
//				document.all("iframeScroller").style.visibility = "visible";
//				document.all("iframeTemp").style.visibility = "visible";
//
//			}
		}
	}
}

function CheckLoaded(p,action){
	if (Loaded)
		CheckAction(p,action);
	else
	{
		Init();
		CheckAction(p,action);
	}
}

function CheckAction(p,action){
	if (action == 'Show')
	{
		if(!IE5 && !NS4 && !NS6)
		{
			SkiftMenuBaggrund(-1,p);
			tal = 0;
		}
		if(IE5)
			showTopFarve(p);
		showObject(p);
	}
	else
	{
		if(IE5)
			hideTopFarve(p);
		hideObject(p);
	}
}
function SkiftMenuBaggrundIE5(farve,td){
	eval("document.all." + td + ".bgColor = '" + farve + "'");
}

function SkiftMenuBaggrund(UnderMenuIndex,HovedMenuIndex){
	var j, p;
	p = eval(HovedMenu[HovedMenuIndex][0]);
	if (p.length > 0)
	{
		HtmlStreng = "<TABLE BORDER = " + MenuRammeTyk + " CELLSPACING = 0 CELLPADDING = 0 BGCOLOR = " + MenuBaggrund + ">";
		for (j = 0; j <= (p.length - 1); j++)
			if (j == UnderMenuIndex)
				HtmlStreng += "<TR bgcolor = " + MenuHighlightFarve + " ><TD onmouseover=SkiftMenuBaggrund(" + j + "," + HovedMenuIndex + ")><nobr><a href=" + p[j][0] + " style=\"" + UnderMenuStyle + "\">" + UnderMenuTekst + "&nbsp;" + p[j][1] + "&nbsp;" + "</A><image HEIGHT=0 WIDTH=0 ></TD></TR>"
			else
				HtmlStreng += "<TR><TD onmouseover=SkiftMenuBaggrund(" + j + "," + HovedMenuIndex + ")><nobr><a href=" + p[j][0] + " style=\"" + UnderMenuStyle + "\">" + UnderMenuTekst + "&nbsp;" + p[j][1] + "&nbsp;" + "</A><image HEIGHT=0 WIDTH=0 ></TD></TR>"
		HtmlStreng += "</TABLE>"
		if (tal == 0)
		{
			document.all[HovedMenu[HovedMenuIndex][1]].innerHTML = HtmlStreng;
			tal = 1;
		}
		else
			tal = 0;
	}
}

function showTopFarve(lagnavn){
	SkiftMenuBaggrundIE5(eval("'" + TopBarFarveHigl + "'"),eval("'td" + HovedMenu[lagnavn][0] + "'"));
}

function hideTopFarve(lagnavn)
{
	SkiftMenuBaggrundIE5(eval("'" + TopBarFarve + "'"),eval("'td" + HovedMenu[lagnavn][0] + "'"));
}

function reloadMenu(){
	if (nnWidth != window.innerWidth || nnHeight != window.innerHeight)
		document.location.reload();
}

var ns4 = (document.layers) ? true : false;

var ok = (navigator.userAgent.indexOf("MSIE") == -1 && document.getElementById) ? true : false;

var bar = "<table align=center BGCOLOR=" + MenuBaggrund + "  cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
var HMT = 0, link;

for ( HMT = 0; HMT <= (HovedMenu.length - 1); HMT++) {
	bar += '<TD id="td' + HovedMenu[HMT][0] + '"  VALIGN=\"top\">'
	bar += '<DIV id="' + HovedMenu[HMT][0] + '" =#ffffff>'
	if (HovedMenu[HMT].length == 4) {
		link = HovedMenu[HMT][3];
		bar += '<a href=' + link + ' CLASS="MenuBar">';
	}
	else {
		link = "javascript:void(0)";
		bar += '<a href=' + link + ' CLASS="MenuBar" onmouseover="CheckLoaded(' + HMT + ',\'Show\');" onmouseout="CheckLoaded(' + HMT + ',\'Hide\')">';
	}
	bar += '&nbsp;' + HovedMenu[HMT][2] + '&nbsp;</a></DIV>';
	if (ok)
		bar += '<DIV id="Under' + HovedMenu[HMT][0] + '" style="position:absolute;visibility:hidden;z-index:2;" onmouseover="CheckLoaded(' + HMT + ',\'Show\')"; ' + 
		'onmouseout="CheckLoaded(' + HMT + ',\'Hide\')"></DIV>';
	bar += '<IMG SRC="/images/tom.gif" ALT="" WIDTH="2" HEIGHT="1" HSPACE="0" VSPACE="0" BORDER="0"></td>';
}

bar += '</tr></table>';

document.write(bar);
