function initMenus() {

	// do not run if dom not supported
	if (!document.getElementsByTagName) return;

	var menus = document.getElementsByTagName("DIV");
	for (var i = 0; i < menus.length; i++)
	{
		// if node is menu class
		var mclass = menus[i].className;
		if (mclass.indexOf("menu") > -1)
		{

			// loop through all siblings until reach main link for current page
			var submenu = menus[i].childNodes;
			gotit = 0;
			for (j = 0; j < submenu.length && gotit==0; j++)
			{
				pageurl = new String(document.location);

				// if there are comma delimiters in the name attribute, use id matching
				if (String(submenu[j].getAttribute("name")).indexOf(",") > -1)
				{
					namesplit = String(submenu[j].getAttribute("name")).split(",");
					pageguid = String(namesplit[0]);
					pageid = String(namesplit[1] + ".asp");
					// check for empty pageid value for items which are not reddot pages
					// and ensure there is no match
					if (pageid == ".asp")
					{
						pageid="thisdoesntmatch.asp";
					};
					//pageid = new String(submenu[j].getAttribute("name") + ".asp");
					//pageguid = new String(submenu[j].getAttribute("name"));

					pageurlidmatch = pageurl.indexOf(pageid);
					pageurlguidmatch = pageurl.indexOf(pageguid);

					if ((pageurlidmatch>-1) || (pageurlguidmatch>-1))
					{
						gotit=1;
					};
				}
				// else use title matching - after id and guid matching was implemented
				else
				{
					if (submenu[j].getAttribute("id")==top.document.title)
					{
						gotit=1;
					};
				};


				if (submenu[j].className=="sub")
				{
					submenu[j].style.display = "none";
				}
				if (submenu[j].className=="sub2")
				{
					submenu[j].style.display = "none";
				}

				if (gotit==1)
				{
					j=j-1;
				};
			}
			// if there has been no match throughout the whole menu, may be a redirect
			// reprocess the menu
			if (gotit!=1)
			{
				for (j = 0; j < submenu.length && gotit==0; j++)
				{
					// use title matching
					if (submenu[j].getAttribute("id")==top.document.title)
					{
						gotit=1;
					};


					if (submenu[j].className=="sub")
					{
						submenu[j].style.display = "none";
					}
					if (submenu[j].className=="sub2")
					{
						submenu[j].style.display = "none";
					}

					if (gotit==1)
					{
						j=j-1;
					};
				}
			}

			// if the previous page is a main or subsection link - skip all subitems which are already open
			if (j < submenu.length && (submenu[j].className == "main" || submenu[j].className == "subsection"))
			{
				submenu[j].childNodes(0).childNodes(0).style.fontWeight = "bold";
				j++;
				while (submenu[j] != null && (submenu[j].className == "sub" || submenu[j].className == "sub2"))
				{
					// leave all subs showing, hide all sub2s
					if (submenu[j].className == "sub")
					{
						submenu[j].style.display = "block";
					}
					if (submenu[j].className == "sub2")
					{
						submenu[j].style.display = "none";
					}
					j++;
				}
			}
			

			// if the current page is a sub - go back to first sub, by stepping back up until the item is no longer a sub or sub2

			// mark where the current page's sub2s start
			subjump=j+1;
			if (j < submenu.length && submenu[j].className == "sub")
			{
				j=j-1;
				while (j > -1 && submenu[j] != null && (submenu[j].className == "sub" || submenu[j].className == "sub2"))
				{
					j=j-1;
				}
				submenu[j].childNodes(0).childNodes(0).style.fontWeight = "bold";
				j++;

				// - open all closed subs under that main
				while (submenu[j] != null && (submenu[j].className == "sub" || submenu[j].className == "sub2" ))
				{
					if (submenu[j].className == "sub")
					{
						submenu[j].style.display = "block";
					}
					j++;
				}

				j=subjump;
				// - then reopen all closed sub2s under that main
				while (submenu[j] != null && submenu[j].className == "sub2")
				{
					submenu[j].style.display = "block";
					j++;
				}
			}

			// if the current page is a sub2 - go back to first sub2
			if (j < submenu.length && submenu[j].className == "sub2")
			{
				// step back to the first sub2
				while (j > -1 && submenu[j] != null && submenu[j].className == "sub2")
				{
					j=j-1;
				}
				// save the return point to reexpand sub2s under that specific sub
				reexpandsub2s=j+1;

				// go back to the main item by stepping back through all subs and sub2s
				while (j > -1 && submenu[j] != null && (submenu[j].className == "sub" || submenu[j].className == "sub2"))
				{
					j=j-1;
				}
				submenu[j].childNodes(0).childNodes(0).style.fontWeight = "bold";
				j++;

				// expand all subs under that main
				while (submenu[j] != null && (submenu[j].className == "sub" || submenu[j].className == "sub2"))
				{
					if (submenu[j].className == "sub")
					{
						submenu[j].style.display = "block";
					}
					j++;
				}

				// jump to return point - and reopen all closed sub2s
				j=reexpandsub2s;
				while (submenu[j] != null && submenu[j].className == "sub2")
				{
					submenu[j].style.display = "block";
					j++;
				}
			}

			// for all items under that main, leave subs open, close sub2s
			while (submenu[j] != null && (submenu[j].className == "sub" || submenu[j].className == "sub2"))
			{
				if (submenu[j].className == "sub")
				{
					submenu[j].style.display = "block";
				}
				if (submenu[j].className == "sub2")
				{
					submenu[j].style.display = "none";
				}
				j++;
			}

			// hide the remaining sub2s
			while (j < submenu.length)
			{
				if (submenu[j].className=="sub" || submenu[j].className=="sub2")
				{
					submenu[j].style.display = "none";
				}
				j++;
			}
		}
	}
}

window.onload = initMenus;
