/*---------------------------------------------------------------------------------
Maintenance Log:
Date		Responsible		Comments
---------------------------------------------------------------------------------
2008
27.Oct.2008		Kintat KO   Yahoo-yui 2.6.0 for CTL's homepage menu system
28.Oct.2008		Kintat KO   add global vars to ctrl x coors.
31.Oct.2008		Kintat KO   add event handlers for menu-related divs.
---------------------------------------------------------------------------------*/

	/* 
		------------------------------------------------------------
	
								Global Vars
	
		------------------------------------------------------------
	*/
	var intXOffset = 125;
	var intYOffset = 322;
	var intMBarItemWidth = 83;	
	
	var oPrevMenu = null;

	var oMenu_aboutus = new YAHOO.widget.Menu("ctl_menu_aboutus",
											  { position: "dynamic", 
												x: intXOffset+(intMBarItemWidth*1), y: intYOffset, 
												showdelay: 100 }
										     );
	var oMenu_progs = new YAHOO.widget.Menu("ctl_menu_progs", 
											{ position: "dynamic", 
											  x: intXOffset+(intMBarItemWidth*2), y: intYOffset, 
											  showdelay: 100,
											  constraintoviewport : false }
										   );
										   
	var oMenu_research = new YAHOO.widget.Menu("ctl_menu_research", 
											   { position: "dynamic", 
												 x: intXOffset+(intMBarItemWidth*3), y: intYOffset, 
												 showdelay: 100,
												 constraintoviewport : false }
											  );
										   
	var oMenu_people = new YAHOO.widget.Menu("ctl_menu_people", 
											 { position: "dynamic", 
											   x: intXOffset+(intMBarItemWidth*4), y: intYOffset, 
											   showdelay: 100 }
										    );
								
	var oMenu_studentLife = new YAHOO.widget.Menu("ctl_menu_studentLife", 
												  { position: "dynamic", 
													x: intXOffset+(intMBarItemWidth*5), y: intYOffset, 
													showdelay: 100 }
												 );
										   
	var oMenu_newsCentre = new YAHOO.widget.Menu("ctl_menu_newsCentre", 
												 { position: "dynamic", 
												   x: intXOffset+(intMBarItemWidth*6), y: intYOffset, 
												   showdelay: 100 }
												);

	/*
		------------------------------------------------------------
			
						Event Handlers for menus
	
		------------------------------------------------------------
	*/
	function ctl_yui_showM() {
		// calling context is implicitly the menu obj added into the listener registry:
		this.render();
		this.show();
		// Chk to see if another previously displayed menu is still displayed: 
		// if so, hide it.
		if (oPrevMenu != null && oPrevMenu != this) {
			oPrevMenu.hide();
		}
		// Set ptr of previous menu to current one:
		oPrevMenu = this;
	}

	// obsolete:
	function ctl_yui_hideM(ev,obj) {
		// context is implicitly the menu obj added into the listener registry:
		if (this != null) {
			this.hide();
		}			
	}
	
	function fnCallback(e) { alert("clicked"); }			// obsolete

	/*
		------------------------------------------------------------
			
					Other customized menu funcs
	
		------------------------------------------------------------
	*/
	
	/*
		TODO: implement an array of opened menu obj ptrs so that
			  hiding them all can be more systematic. [31.Oct.2008]
	*/
	
	// this func will be useful for forcing menu closing when mouse
	// is no longer around the horizontal menubar.
	function ctl_yui_hideAllMs() {
		if (oPrevMenu != null) {
			oPrevMenu.hide();
		}	
	}
										   
	/*
		------------------------------------------------------------
			
							Listener Registration
	
		------------------------------------------------------------
	*/
	
	/* The following registrations must correspond exactly to the graphical elements' IDs on the pg layout: */	
	
	/* (1) indiv menubar items' event registration */
	YAHOO.util.Event.addListener(document.getElementById("menubar_home"), "mouseover", 
								 ctl_yui_hideM, oMenu_aboutus, true);

	YAHOO.util.Event.addListener(document.getElementById("menubar_aboutus"), "mouseover", 
								 ctl_yui_showM, oMenu_aboutus, true);
								 
	YAHOO.util.Event.addListener(document.getElementById("menubar_programmes"), "mouseover", 
								 ctl_yui_showM, oMenu_progs, true);

	YAHOO.util.Event.addListener(document.getElementById("menubar_research"), "mouseover", 
								 ctl_yui_showM, oMenu_research, true);								 
								 
	YAHOO.util.Event.addListener(document.getElementById("menubar_people"), "mouseover", 
								 ctl_yui_showM, oMenu_people, true);
	
	YAHOO.util.Event.addListener(document.getElementById("menubar_studentLife"), "mouseover", 
								 ctl_yui_showM, oMenu_studentLife, true);
	
	YAHOO.util.Event.addListener(document.getElementById("menubar_newsCentre"), "mouseover", 
								 ctl_yui_showM, oMenu_newsCentre, true);
	
	YAHOO.util.Event.addListener(document.getElementById("menubar_contactUs"), "mouseover", 
								 ctl_yui_hideM, oMenu_newsCentre, true);
								 
	/* (2) other menu-related element events' registration */
	
	// Purpose: when mouse is no longer around menubar close any already popped up menus.
	// mouse is substantially beyond menubar:
	YAHOO.util.Event.addListener(document.getElementById("topBannerContainer"), "mouseover", 
								 ctl_yui_hideAllMs);
	
	// mouse is substantially below menubar:
	YAHOO.util.Event.addListener(document.getElementById("pgContentContainer"), "mouseover", 
								 ctl_yui_hideAllMs);
	
	