var persistmenu = "yes" //"yes" or "no". Make sure each DIV 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

if (document.getElementById) {
    document.write('<style type="text/css">\n')
    document.write('.submenu{display: none;}\n')
    document.write('.ssubmenu{display: none;}\n')
    document.write('<\/style>\n')
}

function SwitchMenu(obj,objpict) {
	if (document.getElementById) {
	var el = document.getElementById(obj);
	var ar = document.getElementById("menudiv").getElementsByTagName("div");
	var pictel = document.getElementById(objpict);
	var pictar = document.getElementById("menudiv").getElementsByTagName("a");
		if (el.style.display != "block") {
			for (var i = 0; i < ar.length; i++)
				if (ar[i].className == "submenu") ar[i].style.display = "none";
			el.style.display = "block";
		}
		else el.style.display = "none";

		if (pictel.className.charAt(pictel.className.length - 1) != "3") {
			for (var i = 0; i < pictar.length; i++)
				if (pictar[i].id.substring(0,2) == "ax") pictar[i].className = pictar[i].className.substring(0, pictar[i].className.length - 1) + "2";
			pictel.className = pictel.className.substring(0, pictel.className.length - 1) + "3";
		}
		else pictel.className = pictel.className.substring(0, pictel.className.length - 1) + "2";
	}
}
function CloseMenu() {
	if (document.getElementById) {
	var ar = document.getElementById("menudiv").getElementsByTagName("div");
	var pictar = document.getElementById("menudiv").getElementsByTagName("a");
	for (var i = 0; i < ar.length; i++)
		if (ar[i].className == "submenu" || ar[i].className == "ssubmenu") ar[i].style.display = "none";
	for (var i = 0; i < pictar.length; i++)
		if (pictar[i].id.substring(0,2) == "ax" || pictar[i].id.substring(0,2) == "az") pictar[i].className = pictar[i].className.substring(0, pictar[i].className.length - 1) + "2";
	}
}

function SwitchsubMenu(obj,objpict) {
	if (document.getElementById) {
	var sel = document.getElementById(obj);
	var sar = document.getElementById("menudiv").getElementsByTagName("div");
	var pictel = document.getElementById(objpict);
	var pictar = document.getElementById("menudiv").getElementsByTagName("a");
		if (sel.style.display != "block") {
			for (var i = 0; i < sar.length; i++)
				if (sar[i].className == "ssubmenu") sar[i].style.display = "none";
			sel.style.display = "block";
		}
		else sel.style.display = "none";

		if (pictel.className.charAt(pictel.className.length - 1) != "3") {
			for (var i = 0; i < pictar.length; i++)
				if (pictar[i].id.substring(0,2) == "az") pictar[i].className = pictar[i].className.substring(0, pictar[i].className.length - 1) + "2";
			pictel.className = pictel.className.substring(0, pictel.className.length - 1) + "3";
		}
		else pictel.className = pictel.className.substring(0, pictel.className.length - 1) + "2";
	}
}

function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			returnvalue = unescape(document.cookie.substring(offset, end));
		}
	}
	return returnvalue;
}

function onloadfunction() {
	if (persistmenu == "yes"){
		var cookiename = (persisttype == "sitewide")? "switchmenu": window.location.pathname;
		var cookievalue = get_cookie(cookiename);
		if (cookievalue != "") {
			document.getElementById(cookievalue).style.display = "block";
			var item = new String ("ax" + cookievalue.substring(3, cookievalue.length));
			if (document.getElementById(item)) document.getElementById(item).className = document.getElementById(item).className.substring(0, document.getElementById(item).className.length - 1) + "3";
		}

		var scookiename = (persisttype == "sitewide")? "sswitchmenu": "s"+window.location.pathname;
		var scookievalue = get_cookie(scookiename);
		if (scookievalue != "") {
			document.getElementById(scookievalue).style.display = "block";
			var item = new String ("az" + scookievalue.substring(4, scookievalue.length));
			if (document.getElementById(item)) document.getElementById(item).className = document.getElementById(item).className.substring(0, document.getElementById(item).className.length - 1) + "3";
		}
	}
}

function savemenustate() {
	var inc = 1, blockid="", sinc = 1, sblockid = "";
	while (document.getElementById("sub" + inc)) {
		if (document.getElementById("sub"+inc).style.display == "block") {
			blockid = "sub" + inc;
			break;
		}
		inc++;
	}
	while (document.getElementById("ssub" + sinc)) {
		if (document.getElementById("ssub" + sinc).style.display == "block") {
			sblockid = "ssub" + sinc;
			break;
		}
		sinc++;
	}
	var cookiename = (persisttype == "sitewide")? "switchmenu": window.location.pathname;
	var cookievalue = (persisttype == "sitewide")? blockid + ";path=/": blockid;
	document.cookie = cookiename + "=" + cookievalue;
	var scookiename = (persisttype == "sitewide")? "sswitchmenu": "s" + window.location.pathname;
	var scookievalue = (persisttype == "sitewide")? sblockid + ";path=/": sblockid;
	document.cookie = scookiename + "=" + scookievalue;
}

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;

