function loadLinks()
{
	$('#nav li').each(function() {
		var li = $(this);
		var link = li.children('a').attr('href');
		if (link) {
			li.click(function() {
				document.location.href=link;
			});
		}
	});
}


var border_on="1px solid #000";
var bg_on="#fff";
var topbg_on="#000";
var border_off="1px solid #adad7c";
var bg_off="#ccc";
var topbg_off="#";
var menu_timer;


function MenuTimerFunc(level) {
	this.m_level = level;
}
MenuTimerFunc.prototype.turnOn = function(elementid) {
	this.m_elementid = elementid;
	turnOffFunc = (this.m_level == "top" ? "topMenuTimer" : "subMenuTimer");
	this.menu_timer = setTimeout(turnOffFunc + '.turnOff()',1000);
}
MenuTimerFunc.prototype.turnOff = function() {
	if (this.menu_timer)
		clearTimeout(this.menu_timer);
	this.menu_timer = 0;
	if (this.m_elementid)
	{
		document.getElementById(this.m_elementid).lastChild.style.display="none";
	}
}
var topMenuTimer = new MenuTimerFunc('top');
var subMenuTimer = new MenuTimerFunc('sub');

activateMenu = function(nav) {
	if (document.all&&document.getElementById(nav).currentStyle) {
		// IE9 operates much like FF, so exit out if that's the case
		var ver = parseInt($.browser.version, 10);
		if (ver >= 9) return;
		var navroot = document.getElementById(nav);
		var lis=navroot.getElementsByTagName("LI");
		for (i=0; i<lis.length; i++) {
			lis[i].id = "elem" + i;
			if(lis[i].lastChild.tagName=="UL")
			// it has child UL
			{
				if (lis[i].parentNode != lis[0].parentNode) 
				{
				// it is not top-level menu item
					lis[i].onmouseover=function() {
						subMenuTimer.turnOff();
						this.lastChild.style.display="block";
						this.style.backgroundColor=bg_on;
						this.style.border=border_on;
					}
					lis[i].onmouseout=function() {
						subMenuTimer.turnOn(this.id);
						this.style.backgroundColor=bg_off;
						this.style.border=border_off;
					}
				}
				else
				// it _IS_ a top-level menu item
				{
					lis[i].onmouseover=function() {
						if (topMenuTimer.m_elementid != this.id)
							subMenuTimer.turnOff();
						topMenuTimer.turnOff();
						this.lastChild.style.display="block";
					}
					lis[i].onmouseout=function() {
						topMenuTimer.turnOn(this.id);
					}
				}
			}
			else {
				lis[i].onmouseover=function() {
					this.style.border=border_on;
					this.style.backgroundColor=bg_on;
				}
				lis[i].onmouseout=function() {
					this.style.border=border_off;
					this.style.backgroundColor=bg_off;
				}
			}
		}
	}
}
window.onload=function() {
	loadLinks();
	activateMenu('nav');
}

function isIE()
{
	return (document.all&&document.getElementById('nav').currentStyle);
}

function jump(url)
{
	document.location.href = url;
}

