var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

function initPage()
{
	var n = document.getElementById("navigation");
	if (n)
	{
		var lis = n.getElementsByTagName("li");
		for (var i = 0; i < lis.length; i++)
		{
			if (lis[i].getElementsByTagName("ul").length)
			{
				var a = lis[i].getElementsByTagName("a").item(0);
				if (a)
				{
					a.onclick = function ()
					{
						var p = this.parentNode;
						if (p.className.indexOf("active") != -1)
							p.className = p.className.replace("active", "");
						else
							p.className += " active";
						return false;
					}
				}
			}
		}
	}
}

if (window.addEventListener) {
	window.addEventListener("load", initPage, false);
	window.addEventListener("load", initImg, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", initPage);
	window.attachEvent("onload", initImg);
}

var _list = null;
var _img = null;

function initImg() {
	_list = document.getElementById("select");
	_img = document.getElementById("select-img");
	if(_list && _img)
	{
		var links = _list.getElementsByTagName("a");
		for(i = 0; i < links.length; i++)
		{
			if (links[i].href.indexOf("#") == -1)
			{
				links[i].onclick = function() {
					_img.src = this.href;
					return false;
				};
			}
		}
	}
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "navigation" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "navigation" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate