// CONFIGURABLE CONSTANTS

var menuID		= 'menu';			// the ID of the UL menu
var menuLeftID	= 'left-menu';		// the ID of the UL menu

// INITIALIZE MENU
// set the events (onmouseover, onmouseout) on the menu
window.onload = function() {
	$(document).ready(
		function() {


			/***** TOP MENU *****/

			// Cycle of the 1st LIs of the 1st UL menu
			$('#' + menuID + ' ul > li').each(function(i) {
				if ($(this).children(':last')[0].tagName == 'UL') {
					// Set the mouse events
					this.onmouseover = function() {
						$(this).children(':last')[0].style.display = "block";
					}
					this.onmouseout = function() {
						$(this).children(':last')[0].style.display = "none";
					}
				}
			});


			/***** LEFT MENU *****/

			var showed1;		// Refference of one of the 1st submenu which is currently showed
			var showed2;		// Refference of one of the 2nd submenu which is currently showed

			// Cycle of the 1st LIs of the 1st UL menu
			$('#' + menuLeftID + ' > li').each(function(i) {
				if ($(this).children(':last')[0].tagName == 'UL') {
					var UL1timer = false;
					// Set the mouse events
					this.onmouseover = function() {
						if (showed1) {
							clearTimeout(UL1timer);
							hideSubmenu(showed1);
						}
						$(this).children(':last')[0].style.display = "block";
						showed1 = this;
					}
					this.onmouseout = function() {
						li1Obj = this;
						UL1timer = setTimeout('hideSubmenu(li1Obj)', 100);
					}

					// Cycle of the 2nd ULs menus
					$('> ul', this).each(function(i) {
						// Cycle of the 2nd LIs of the 2nd UL menu
						$("> li", this).each(function(i) {
							if ($(this).children(':last')[0].tagName == 'UL') {
								var UL2timer = false;
								// Set the mouse events
								this.onmouseover = function() {
									if (showed2) {
										clearTimeout(UL2timer);
										hideSubmenu(showed2);
									}
									$(this).children(':last')[0].style.display = "block";
									showed2 = this;
								}
								this.onmouseout = function() {
									li2Obj = this;
									UL2timer = setTimeout('hideSubmenu(li2Obj)', 100);
								}
							}
						});
					});
				}
			});

		}
	);
}


function hideSubmenu(id) {
	$(id).children(':last')[0].style.display = "none";
}