var MSIE = (navigator.appName == "Microsoft Internet Explorer");
var menu_nr = MSIE?0:1;
var s, t;

function openMenu(){
	if(t != null){
		t.childNodes[menu_nr + 0].className = "";
	}
	if(s != null){
		s.style.display = "none";
	}
	this.className = "selected";
	t = this.parentNode;
	s = t.childNodes[menu_nr + 2];
	reposition();
	s.style.display = "block";
	if (document.getElementById("menu").getElementsByTagName('UL')[0].clientHeight < s.clientHeight) document.getElementById("menu").getElementsByTagName('UL')[0].style.height = s.clientHeight + 'px';
	return false;
}

function reposition(){
	var x, y;
	if (t != null && document.styleSheets[1].href.indexOf('jong')==-1) {
		if(!MSIE){
			x = t.parentNode.offsetLeft;
			y = t.parentNode.offsetTop;
		}else{
			x = t.parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft;
			y = t.parentNode.parentNode.parentNode.parentNode.offsetTop + 5;
		}
	//	alert("(" + x + "," + y + ")");
		s.style.left = x + "px";
		s.style.top = y + "px";
	}
}

function setupMenu(){
	var menu = document.getElementById("menu").childNodes[menu_nr];
	for(var i = 0 + menu_nr; i < menu.childNodes.length; i++){
		if(menu.childNodes[i].childNodes.length > 0 + menu_nr){
			var menuHREF = menu.childNodes[i].childNodes[0 + menu_nr].href;
			if(menuHREF.substr(0, menuHREF.lastIndexOf('/')+1) == unescape(location.href).substr(0, unescape(location.href).lastIndexOf('/')+1)) {
				menu.childNodes[i].childNodes[0 + menu_nr].className = "selected";
				if(menu.childNodes[i].childNodes[menu_nr + 2]){
					menu.childNodes[i].childNodes[0 + menu_nr].onclick = openMenu;
					t = menu.childNodes[i];
					s = t.childNodes[menu_nr + 2];
					reposition();
					s.style.display = "block";

					for(var ii = 0 + menu_nr; ii < s.childNodes.length; ii++){
						if(s.childNodes[ii].childNodes[0]) {
							if(s.childNodes[ii].childNodes[0].href == unescape(location.href)) {
								s.childNodes[ii].childNodes[0].className = "selected";
							}
						}
					}
				}
			}
		}
	}

	if(document.addEventListener){
		window.addEventListener("resize", reposition, false);
	}else{
		document.body.onresize = reposition;
	}
}

function initAll() {
	the_background = document.getElementById('bg_photo');
	if (bgArray) if (bgArray.length != 0) randomBG();
	theContent = document.getElementById('content');
}

function randomBG() {
	var bgchoice = Math.round((bgArray.length-1)*Math.random());
	if (document.styleSheets[1].href.indexOf('jong')==-1) {
		bgcolor = "transparent"
	} else {
		bgcolor = "#fff"
	}
	the_background.style.background = bgcolor + " url("+bgArray[bgchoice]+") 100% 100% no-repeat";
}

function printpage() {
	
	strNewWindow = '<?xml version="1.0" encoding="utf-8"?>\n';
	strNewWindow = strNewWindow + '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n';
	strNewWindow = strNewWindow + '<html>\n';
	strNewWindow = strNewWindow + '<head>\n';
	strNewWindow = strNewWindow + '<title></title>\n';
	for (count=0; count < document.styleSheets.length; count++)
	{
		strNewWindow = strNewWindow + '<link href="' +document.styleSheets[count].href+ '" rel="stylesheet" type="text/css"/>\n';
	}
	strNewWindow = strNewWindow + '</head>\n';
	strNewWindow = strNewWindow + '<body class="print" onload="javascript:this.window.print(),self.close();">\n';
	strNewWindow = strNewWindow + '<img src="/binary/FNV_Logo_WB.gif" alt="FNV" /><br \>\n';
	
	strNewWindow = strNewWindow + '<!-- start of print -->\n';
	strNewWindow = strNewWindow + '<div id="content" style="border:none;">\n';
	strNewWindow = strNewWindow + document.getElementById('content').innerHTML + '\n';
	strNewWindow = strNewWindow + '</div>\n';
	strNewWindow = strNewWindow + '<!-- end of print -->\n';
	
	strNewWindow = strNewWindow + '</body>\n';
	strNewWindow = strNewWindow + '</html>\n';

	PopWin = window.open('','Print','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=650,left=200,top=150');
	PopWin.document.write(strNewWindow);
	PopWin.document.close();
	return false;
}

function popup(url,name,w,h) {
	PopWin2 = window.open(url,name,'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+w+',height='+h+',left = 200,top = 150');
}

if (window.addEventListener) window.addEventListener("load", initAll, false)
else if (window.attachEvent) window.attachEvent("onload", initAll)
else if (document.getElementById) window.onload = initAll