var isMozilla;

/******************************************
Function name : generateMenu
Return type : None
Comments : Function generates onmouseover & onmouseout events for menu.
User instruction : generateMenu(selectedMenu)
******************************************/
generateMenu = function(selectedMenu) { 

  // alert(selectedMenu);
   //get the menu navigation root
	navRoot = document.getElementById(selectedMenu);
	//alert(selectedMenu)
	//find the menu navigation root, if found then enter here
	if(navRoot)
	{
		//alert(navRoot.childNodes.length);
		//get the childNodes of the navigation root 
		//start the loop and continue till the count of childNodes 
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			//get the current node
			node = navRoot.childNodes[i];
			
			//if the node is a <li> tag, so we process the menu
			if (node.nodeName=="LI")
			{
				//if the node id != menu, so we process the menu
				if(node.id!='')
				{
					//check the browser
					isMozilla = (document.all) ? 0 : 1;
					
					//write the onmouseover event code for current node
					node.onmouseover=function() {
						
						//change the selected menu class to unselect it
						document.getElementById(selectedMenu).className="remove_current";
						
						//hide the sub menu of this selected menu
						hideMenu('sub_'+selectedMenu);
						
						//if the browser is mozilla
						if(isMozilla)
						{
							//open menu for current node
							openMenu('sub_'+this.id);
							
							//change the class of this node.
							tmpClass[this.id] = document.getElementById(this.id).className;
							document.getElementById(this.id).className="general";
						}
						else
						{
							//change the class of this node.
							tmpClass[this.id] = this.className;
							this.className = "general over";
						}
					}
					
					//write the onmouseout event code for current node
					node.onmouseout=function() {
						
						//change back the selected menu class to again select it
						document.getElementById(selectedMenu).className="current";
						if(this.id != selectedMenu)
						{
							if(isMozilla)
							{
								//hide menu for current node
								hideMenu('sub_'+this.id);
								
								//change the class of this node.
								document.getElementById(this.id).className= tmpClass[this.id];
							}
							else
							{
								//change the class of this node.
								this.className = tmpClass[this.id];
							}
							//open the sub menu of this selected menu
							openMenu('sub_'+selectedMenu);
						}
						
					}
				}
			}
		}
	}
	//send an alert that menu system not found
	else
	{
		alert('Menu system not found. Please check your code.');
	}
}

/******************************************
Function name : openMenu
Return type : None
Comments : Function will open the menu as described by the selectMenu element.
User instruction : openMenu(selectMenu)
******************************************/
openMenu = function(selectMenu) {

	//get the selectMenu element on document
	displayMenu = document.getElementById(selectMenu);
	
	//if found change the style of this element
	if(displayMenu)
	{
		displayMenu.style.display="block";
	}
}

/******************************************
Function name : hideMenu
Return type : None
Comments : Function will hide the menu as described by the selectMenu element.
User instruction : hideMenu(selectMenu)
******************************************/
hideMenu = function(selectMenu) {
	
	//get the selectMenu element on document
	displaySubMenu = document.getElementById(selectMenu);
	
	//if found change the style of this element
	if(displaySubMenu)
	{
		displayMenu.style.display="none";
	}	
}
