/* ================================================================ 
This copyright notice must be untouched at all times.

The original version of this scriptt and the associated (x)html
is available at http://www.stunicholls.com/menu/simple.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */

clickMenu = function(menu) {
	var getEls = document.getElementById(menu).getElementsByTagName("LI");
	var getAgn = getEls;

	if (getEls.length>0)
		// if the page has loaded the menu then observe clicks outside of menu
		// so we can hide dropdowns when user clicks away
	{
		hideMenuClick();
	}

	for (var i=0; i<getEls.length; i++) {
			getEls[i].onclick=function() {
				for (var x=0; x<getAgn.length; x++) {
				getAgn[x].className=getAgn[x].className.replace("unclick", "");
				getAgn[x].className=getAgn[x].className.replace("wb_hover", "unclick");
				}
			if ((this.className.indexOf('unclick'))!=-1) {
				this.className=this.className.replace("unclick", "");;
				}
				else
				{
					this.className+="wb_hover";
				}
			}
		}
	}

function hideMenuClick()	{
	Event.observe(document.body, 'click', function(event) {
	  var elt = $(Event.element(event));
	  var eltTag = elt.tagName

		var elt = Event.findElement(event, 'main');
		if (eltTag != 'A' && eltTag != 'SPAN')
			{
			hideMenu();
			}
	});
}

function hideMenu()	{
	$$('.wb_hover').each(function(item){
	item.className='';
	});
}