var menu_cur = "";
var menu_hide_timeout = 0;
function menu_get_position(n){
	var pos = new Object();
	pos.x = n.offsetLeft;
	pos.y = n.offsetTop;
	n = n.offsetParent;
	while (n){
		pos.x += n.offsetLeft;
		pos.y += n.offsetTop;
		n = n.offsetParent;
	}
	return pos;
}
function menu_hide(prefix){
	window.clearTimeout(menu_hide_timeout);
	var tmp = prefix;
	while (tmp.length<menu_cur.length){
		var pos = menu_cur.indexOf("_",tmp.length+1);
		if (pos==-1){
			tmp = menu_cur;
		}
		else {
			tmp = menu_cur.substr(0,pos);
		}
		var popup = null;
		var node = null;
		if (document.all){
			popup = document.all['menu_'+tmp];
			node = document.all[tmp];
		}
		else{
			popup = document.getElementById('menu_'+tmp);
			node = document.getElementById(tmp);
		}
		if (node){
			if (node.firstChild&&node.firstChild.nodeName.toLowerCase()=="img"){
				var src = node.firstChild.src;
				if (src.substr(src.length-9,6)=="_over."){
					node.firstChild.src = src.substr(0,src.length-9)+src.substr(src.length-4);
				}
			}
			else if (node.nodeName.toLowerCase()=="img"){
				var src = node.src;
				if (src.substr(src.length-9,6)=="_over."){
					node.src = src.substr(0,src.length-9)+src.substr(src.length-4);
				}
			}
			var cls = node.className + " ";
			node.className = cls.replace(/menu-item-over /g,"menu-item ");
		}
		if (popup)
			popup.style.display = 'none';
	}
	menu_cur = prefix;
}
function menu_show(name,dx,dy){
	var prefix = 0;
	while (prefix<name.length && prefix<menu_cur.length){
		var p = name.indexOf("_",prefix+1);
		if (p==-1)
			p = name.length;
		if (name.substr(0,p)!=menu_cur.substr(0,p))break;
		prefix = p;
	}
	menu_hide(name.substr(0,prefix));
	menu_cur = name;
	if (!name)return;
	var tmp = "";
	while (tmp!=name){
		var pos = name.indexOf("_",tmp.length+1);
		if (pos==-1){
			tmp = name;
		}
		else {
			tmp = name.substr(0,pos);
		}
		var popup = null;
		var node = null;
		if (document.all){
			popup = document.all['menu_'+tmp];
			node = document.all[tmp];
		}
		else{
			popup = document.getElementById('menu_'+tmp);
			node = document.getElementById(tmp);
		}
		if (!node)return;
		if (node.firstChild&&node.firstChild.nodeName.toLowerCase()=="img"){
			var src = node.firstChild.src;
			if (src.substr(src.length-9,6)!="_over." && src.substr(src.length-11,8)!="_active."){
				node.firstChild.src = src.substr(0,src.length-4)+"_over"+src.substr(src.length-4);
			}
		}
		else if (node.nodeName.toLowerCase()=="img"){
			var src = node.src;
			if (src.substr(src.length-9,6)!="_over." && src.substr(src.length-11,8)!="_active."){
				node.src = src.substr(0,src.length-4)+"_over"+src.substr(src.length-4);
			}
		}
		var cls = node.className + " ";
		node.className = cls.replace(/menu-item /gi,"menu-item-over ");
		if (!popup)return;
		var pos = menu_get_position(node);
		popup.style.display = '';
		if (tmp!=name)continue;
		popup.style.left = pos.x+dx+'px';
		popup.style.top = pos.y+dy+'px';
	}
}
function menu_over(node){
	if (!node)return;
	var dx = 2;
	switch (node.id)
	{
	case "about":
		dx = -10;
		break;
	case "gardens":
		dx = -8;
		break;
	case "help":
		dx = -6;
		break;
	}
	menu_show(node.id, dx, 45-9);
}
function menu_out(node){
	menu_hide_timeout = window.setTimeout('menu_hide("")',200);
}
function menu_click(node){
	if (node){
		if (node.nodeName.toLowerCase()!="a"){
			var n = node.firstChild;
			while (n){
				if (menu_click(n))return true;
				n = n.nextSibling;
			}
		}
	}
	else {
		window.location = node.href;
		return true;
	}
	return false;
}
function menu_over_name(name){
	var n = null;
	if (document.all)
		n = document.all[name];
	else if (document.getElementById)
		n = document.getElementById(name);
	if (!n)return;
	if (typeof n.onmouseover!="function")return;
	n.onmouseover();
}

window.onload = function(){
	var n = document.all?document.all['subnav']:document.getElementById('subnav');
	if (!n)return;
	if (!n.tBodies)return;
	n = n.tBodies[0];
	if (!n)return;
	n = n.firstChild;
	while (n)
	{
		if (n.nodeName.toLowerCase()=="tr")
		{
			var n1 = n.firstChild;
			while (n1)
			{
				if (n1.nodeName.toLowerCase()=="td" && n1.className=="subnav-item")
				{
					n1.onmouseover = function(){
						this.className = "subnav-item subnav-item-over";
					}
					n1.onmouseout = function(){
						this.className = "subnav-item";
					}
					n1.style.cursor = "pointer";
					n1.onclick = function(){window.location=this.firstChild.href;}
				}
				else if (n1.nodeName.toLowerCase()=="td" && n1.className=="subnav-first-item")
				{
					n1.onmouseover = function(){
						this.className = "subnav-first-item subnav-item-over";
					}
					n1.onmouseout = function(){
						this.className = "subnav-first-item";
					}
					n1.style.cursor = "pointer";
					n1.onclick = function(){window.location=this.firstChild.href;}
				}
				else if (n1.nodeName.toLowerCase()=="td" && n1.className=="subnav-last-item")
				{
					n1.onmouseover = function(){
						this.className = "subnav-last-item subnav-item-over";
					}
					n1.onmouseout = function(){
						this.className = "subnav-last-item";
					}
					n1.style.cursor = "pointer";
					n1.onclick = function(){window.location=this.firstChild.href;}
				}
				n1 = n1.nextSibling;
			}
		}
		n = n.nextSibling;
	}
  
  //Init for styleswitcher.js
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);

}
