/*-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ Copyright 2008 Jerome Thorp - used only with permission
+ Javascript Menu Object: Vertical form
+ Requires:  prototype.js
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*/
// Menu Constructor
	gomenu = function (curNode, subLevel)
	{
		// Menu Levels for class names
		var smLevel = 'SL'+subLevel;
		//  What our current node is
		var eCurNode = $(curNode);

		if (eCurNode.nodeName == "UL" && eCurNode.id != curNode){
			// Hide the block
			
			if (eCurNode.up("LI").down("A").href == location.href) {eCurNode.style.display = "block";} else {eCurNode.style.display = "none";}
			eCurNode.immediateDescendants().each(function(i){if (i.down().href == location.href){eCurNode.style.display = "block";}})
			
			// add the class name and increment level count
			eCurNode.addClassName(smLevel);
			subLevel++;
		}

		// This is where the click actions are bound to links
		if (eCurNode.nodeName == "LI") {
			Event.observe($(eCurNode.down(0)), 'click', MenuActions.click.bindAsEventListener(MenuActions, eCurNode.down(), eCurNode.down().href));
		}

		// Recursion
		if (eCurNode.immediateDescendants != null) {
			if (eCurNode.immediateDescendants().length > 1) {
				eCurNode.immediateDescendants().each(function(i){gomenu(i, subLevel);})
			}
		}
	}

	// This is where we define what happens in the case of bound events
	var MenuActions = {
		click: function (evt, Node, deText) {
			if ($(Node).next('ul')) {
			//	var eSiblingUL = $(Node).next('ul');
			//	var eSiblingULDisplay = "none";
			//	if (eSiblingUL.style.display) { eSiblingULDisplay = eSiblingUL.style.display;}
	
			//	if (eSiblingULDisplay == "none") {
			//		eSiblingUL.style.display = 'block';
			//		$(Node).addClassName('over');
			//	} else {
			//		eSiblingUL.style.display = 'none';
			//		$(Node).removeClassName('over');
			//	}
			} else {
				// Customize this for the click behavior you want.
				// Uncomment to have 'dead links'
				//$(Node).href = '#' return false;
			}
		}
	}

	// Invocations of JS Menu
	// gomenu function has the ID which is the id of the menu, then 'mouseover' or 'click' to tell what event will transform the menu then the number 0 for the starting sublevel (must always be 0)
	Event.observe(window, 'load', function() {gomenu('smenu', 0);});