var menu_open = {

	x: null,
	ul: null,

	init: function() {

		// the elements we're dealing with

		// Finds the main nav UL
		this.ul = $("event").getElementsByTagName("ul")[0];
		Element.extend(this.ul);

		this.centerNav();

		// Lists all the LI's for the main nav
		var lis = this.ul.immediateDescendants();

		//Loop through the main LI's to find nested UL's. If any, hide them
		for(i=0; i < lis.length; i++) {

			var sub_uls = lis[i].getElementsByTagName("ul");

			if(sub_uls.length > 0) {
				Element.extend(sub_uls[0]);
				//sub_uls[0].hide();
			}

			// Show submenus on mouse over
			lis[i].onmouseover = function() {

				var sub_uls = this.getElementsByTagName("UL");

				if(sub_uls.length > 0)
				{
					Element.extend(sub_uls[0]);
					//sub_uls[0].show();
					sub_uls[0].style.display = "block";
				}

			}


			// Hide submenu's on mouse out
			lis[i].onmouseout = function() {

				var sub_uls = this.getElementsByTagName("ul");

				if(sub_uls.length>0)
				{
					Element.extend(sub_uls[0]);
					//sub_uls[0].hide();
					sub_uls[0].style.display = "none";
				}

			}
		}

	},

	centerNav: function() {

		var leftPos = (this.ul.parentNode.getWidth() - this.ul.getWidth()) / 2;

		this.ul.setStyle({
			left: leftPos + "px"
		});

	}


}

menu_open.init();