

		/*
                 Initialize and render the Menu when its elements are ready 
                 to be scripted.
            */
			
			var oMenu;
			var REFRESH_JSON = false;
			
			function hideOtherMenus(activeMenuIndex) {
				var visibleMenus = YAHOO.widget.MenuManager.getVisible();
				for(var visibleMenu in visibleMenus) {
					//alert("activeItem.id: " + activeItem.id + " compare to " + visibleMenu.id);
					
					//visibleMenu on menu = undefined
					//visibleMenu on submenus= sub1, sub0
					
					//o.argument.menuIndex = 0, 1, 2
					//activeItem.id = /path/to/json/file
					var comparisonId = "sub"+activeMenuIndex;
					
					if(visibleMenu != "left-nav" && comparisonId != visibleMenu) {
						//Hide the visible menu that isn't this one
						YAHOO.widget.MenuManager.getMenu(visibleMenu).hide();
					}
				}
			}
			
            YAHOO.util.Event.onContentReady("sidebar", function () {
                /*
                     Instantiate a Menu:  The first argument passed to the 
                     constructor is the id of the element in the page
                     representing the Menu; the second is an object literal 
                     of configuration properties.
                */
                
				var menuitems = [ {text:"Destination", id: PROGRAM_INSTAL_PATH+"ajax/destination.json"},{text:"Hotel Chain", id: PROGRAM_INSTAL_PATH+"ajax/hotel-chain.json"},{text:"Couples Only", id: PROGRAM_INSTAL_PATH+"ajax/couples.json"}, {text:"Families", id: PROGRAM_INSTAL_PATH+"ajax/families.json"}, {text:"Honeymoon", id: PROGRAM_INSTAL_PATH+"ajax/honeymoon.json"}, {text:"Adults Only", id: PROGRAM_INSTAL_PATH+"ajax/adults.json"} ];
				
				
				oMenu = new YAHOO.widget.Menu( "left-nav", {
					position: "dynamic", 
					clicktohide: false, 
					autosubmenudisplay: true, 
					hidedelay: 0, 
					submenuhidedelay: 250, 
					context: ["left-bar", "tl", "tl"], 
					lazyload: true, 
					iframe: false, 
					scrollincrement: 5000, 
					visible: true, 
					constraintoviewport: false, 
					effect: { 
						effect: YAHOO.widget.ContainerEffect.FADE,
						duration: 0.25
					}
				});
				oMenu.addItems(menuitems);
				
				YAHOO.widget.MenuManager.addMenu(oMenu);
				
				// Adds submenus to existing menu items
				var addSubMenus = function (ev, aArgs) {
					
					var oMenuItem = aArgs[1];
					
					if (oMenuItem && !oMenuItem.cfg.getProperty("submenu")) {
						var jsonUrl = oMenuItem.id;
						if(REFRESH_JSON) {
							var d = new Date();
							jsonUrl += "?"+d.getTime();
						}
						document.body.style.cursor = 'wait';
						var request = YAHOO.util.Connect.asyncRequest('GET', jsonUrl, { 
																success:handleSuccess, 
																failure:handleFailure,
																argument:{menuIndex: oMenuItem.index}
															});
					} else {
						hideOtherMenus(oMenuItem.index);
					}
				};

				oMenu.mouseOverEvent.subscribe( addSubMenus );
				
				var handleSuccess = function(o) {
					if(o.responseText !== undefined) {
						var data;
						if(YAHOO.lang.JSON.isValid(o.responseText)) {
							try {
								data = YAHOO.lang.JSON.parse(o.responseText);
							} catch (e) {
								alert(e);
								document.body.style.cursor = 'default';
							}
						} else {
							alert("Invalid JSON");
							document.body.style.cursor = 'default';
						}
						
						var activeItem = oMenu.getItem(o.argument.menuIndex);
						if(!activeItem.cfg.getProperty("submenu")) {
							activeItem.cfg.setProperty( "submenu", { id: "sub" + o.argument.menuIndex, itemdata: data});
							activeItem.cfg.getProperty("submenu").show();
						
							hideOtherMenus(o.argument.menuIndex);
						}
						
						document.body.style.cursor = 'default';
					}
				}

				var handleFailure = function(o){ 
					if(o.responseText !== undefined){ 
						alert("Status code message: " + o.statusText); 
					}
					document.body.style.cursor = 'default';
				}
				
				
			})
