// primary/secondary navigation

var lastmenu="";
var m_interval = null;

function hidemenu() {
  if (m_interval != null)
  {
    window.clearInterval (m_interval);
    m_interval = null;
  }
  ticks = 0;

	if (document.getElementById(lastmenu)) {
		document.getElementById(lastmenu).style.display="none";
	}
	lastmenu="";
}

function showmenu(menuname) {
  if (m_interval != null)
  {
    window.clearInterval (m_interval);
    m_interval = null;
  }

	if (menuname!=lastmenu) {
		if (document.getElementById(lastmenu)) {
			document.getElementById(lastmenu).style.display="none";
		}
	
		document.getElementById(menuname).style.display="block";
		lastmenu=menuname;
	
		ticks=0;
	}
}

var folder;
folder=window.location.href;
folder=folder.replace(/^http:\/\/[^\/]+\//,"");
folder=folder.replace(/\/.*$/,"")

var topfolder=folder.replace(/\/[^\/]*$/,"");
if (topfolder=="default.htm") topfolder="";

	
if (document.getElementById("menu"+topfolder)) {
	showmenu("menu"+topfolder);
} else {
	document.getElementById("menuhome").style.display="none";
}


var ticks=0;

function timer() {
	if (ticks>0) {
		ticks++;
		if (ticks>5) {
			ticks=0;
			hidemenu();
		}
	}
}

function tryhidemenu() {
  if (m_interval != null)
  {
    window.clearInterval (m_interval);
    m_interval = null;
  }

	ticks=1;
  m_interval = window.setInterval ("timer();", 150);
}


// tertiary navigarion

var lastsubmenu=null;
var lastclicktime=0;

function hasarrow(p) {
	var i;
	for (i=0; i<p.childNodes.length; i++) {
		if (p.childNodes[i].nodeName=="IMG" && p.childNodes[i].src.match(new RegExp("arrow.*gif$","i"))) {
			return p.childNodes[i];
		}
	}
	return false;
}

function menuonclick(e) {
	
	var thisclicktime=new Date();
	
	if (thisclicktime-lastclicktime>500) {
		lastclicktime=thisclicktime;
	
		if (!e) e=window.event;
		var p = (window.event) ? e.srcElement : e.target;	
		p=p.parentNode;
	
		if (p.nodeName != "P") p=p.parentNode;
		
		var newdisplay=toggle(p);
		
		if (newdisplay=="block") {
			if (lastsubmenu) toggle(lastsubmenu);
			lastsubmenu=p;
		} else if (newdisplay=="none") {
			lastsubmenu=null;
		}
	}
		
	return false;
}

function toggle(p) {
	var arrow=hasarrow(p);
	
	var newdisplay="";
	
	if (arrow) {
		if (arrow.src.match(new RegExp("arrowright\.gif$","i"))) {
			arrow.src="/images/arrowdown.gif";
			newdisplay="block";
		} else if (arrow.src.match(new RegExp("arrowdown\.gif$","i"))) {
			arrow.src="/images/arrowright.gif";
			newdisplay="none";
		}
		
		if (newdisplay!="") {
			var i=p.nextSibling;
			while (i) {
				if (hasarrow(i) || i.className=="rule" || i.className=="subhead1") { // found another menu item, divider or header; stop.
					break;
				} else { // this is child of menu; change visibility.
					if (i.style) {
						i.style.display=newdisplay;
					}
				}
				i=i.nextSibling;
			}
		}
	}
	
	return newdisplay;
}

function initmenu() {
	var content=document.getElementById("content");
	
	var i=0;
	
	while (true) {
		if (i>=content.childNodes.length) break;
		if (hasarrow(content.childNodes[i])) {
			// set menu events
			
			content.childNodes[i].onclick=menuonclick;
			
			// hide menu children
			while (true) {
				i++;
				if (i>=content.childNodes.length) break;
				if (hasarrow(content.childNodes[i]) || content.childNodes[i].className=="rule" || content.childNodes[i].className=="subhead1") {
					// found another menu item, divider or header; stop.
					break;
				} else {
					// this is child of menu; hide.
					if (content.childNodes[i].style) {
						content.childNodes[i].style.display="none";
						content.childNodes[i].style.marginLeft="15px";
					}
				}
			}
		} else {
			i++;
		}
	}	
}