
	//Global array to track what menus are currently open.
	var nowOpenMenus = Array();
	var openMenuCount = 0;
	
	//Mouse positions.
	var tempX = 0;
	var tempY = 0;
	
	function popMenu (menuId,theMenu,theObj,subMenu,inOrOut){
	
		var testObj = document.getElementById (menuId);
		if (testObj){
			/*
			//Remove any sub-elements.
			removeElement (menuId);
			
			if (!subMenu){
				//Run through and delete all sub menus.
				for (var i = 0; i < theMenu.length; i++){
					//Split the options by ":";
					var splitMenu = theMenu[i].split (":");
					if (splitMenu[3]){
						removeElement (splitMenu[3]);
					}
				}
			}
			*/
		} else {
		
			//Close all other menus.
			if (!subMenu){
				closeMenus ();
				openMenuCount=0;
			}			 
	
			var newMenu = document.createElement ("div");
			newMenu.className = "pop_up_menu";
			newMenu.id = menuId;
			
			//Add to the list of open menus.
			nowOpenMenus[openMenuCount] = menuId;
			openMenuCount++;
			
			var endHTML = "<div class=\"pop_up_menu_top\"></div>";
			endHTML += "<div class=\"pop_up_menu_middle\">";
			
			//Build the array of menu items.
			for (var i = 0; i < theMenu.length; i++){
				//Split the options by ":";
				var splitMenu = theMenu[i].split (":");
				
				//The end class should not include the line.
				if (i == (theMenu.length - 1)){
					var className = "pop_up_menu_item_last";
					var overClassName = "pop_up_menu_item_last_over";
				} else {
					var className = "pop_up_menu_item";
					var overClassName = "pop_up_menu_item_over";
				}
				
				//First item does not need as much top padding.
				if (i == 0){
					var padClass = "pop_up_menu_item_pad_first";
				} else {
					var padClass = "pop_up_menu_item_pad";
				}
				
				if (splitMenu[1] == "true"){
				
					endHTML += "<div onmouseover=\"this.className='"+overClassName+"';\" onclick=\"popMenu ('"+splitMenu[3]+"',"+splitMenu[2]+","+null+",'"+menuId+"');\" onmouseout=\"this.className='"+className+"'\" class=\""+className+"\"><div class=\""+padClass+"\">";
					endHTML += "<div class=\"pop_up_menu_item_left\">"+splitMenu[0]+"</div>";
					endHTML += "<div class=\"pop_up_menu_item_right\"><img src=\"images/menu_arrow.png\" /></div>";
					endHTML += "<br class=\"clear\" />";
				} else {
				
					if (splitMenu[4] != "null"){
						endHTML += "<div onmouseover=\"this.className='"+overClassName+"'\" onmouseout=\"this.className='"+className+"'\" class=\""+className+"\" onclick=\"closeMenus (); window.location.href='"+splitMenu[4]+"';\"><div class=\""+padClass+"\">";
					} else {
						endHTML += "<div onmouseover=\"this.className='"+overClassName+"'\" onmouseout=\"this.className='"+className+"'\" class=\""+className+"\"><div class=\""+padClass+"\">";
					}
					endHTML += splitMenu[0];
				}
				endHTML += "</div></div>";
			}
			
			endHTML += "</div>";
			endHTML += "<div class=\"pop_up_menu_bottom\"></div>";
			
			newMenu.innerHTML = endHTML;
			
			//X,Y Coords.
			if (theObj){
				var x = findPosX (theObj);
			} else {
				
				var tObj = document.getElementById(subMenu);
				if (tObj){
					var x = ((parseInt (findPosX (tObj)) + parseInt (tObj.offsetWidth))+1);
				}
			}
			
			if (inOrOut){
			
				newMenu.style.top = "123px";
				newMenu.style.left = (x-10)+"px";
			
			} else {

				newMenu.style.top = "167px";
				newMenu.style.left = (x-7)+"px";
				
			}
			
			document.body.appendChild (newMenu);
		}
		
	}
	
	//Function to close all menus.
	function closeMenus (leaveOpen){
		for (var i = 0; i < nowOpenMenus.length; i++){
			if (nowOpenMenus[i] != leaveOpen){
				removeElement (nowOpenMenus[i]);
			}
		}
	}
	
	//Function to find the x coordinate of an object.  Pass in by ID.
	function findPosX(obj){
		var tempObj = obj;
		if (tempObj){
			obj = tempObj;
			var curleft = 0;
			if (obj.offsetParent){
				while (obj.offsetParent){
					curleft += obj.offsetLeft
					obj = obj.offsetParent;
				}
			} else if (obj.x){
				curleft += obj.x;
			}
			return curleft;
		} else {
			return false;
		}
	}
	
	//Function to find the y coordinate of an object.  Pass in by ID.
	function findPosY(obj){
		var tempObj = obj;
		if (tempObj){
			obj = tempObj;
			var curtop = 0;
			if (obj.offsetParent){
				while (obj.offsetParent){
					curtop += obj.offsetTop
					obj = obj.offsetParent;
				}
			} else if (obj.y){
				curtop += obj.y;
			}
			return curtop;
		} else {
			return false;
		}
	}
	
	//Function to remove an elemnet by id.
	function removeElement (theid){
		var em = document.getElementById(theid);
		if (!em){
			em = parent.document.getElementById(theid);
		}
		if (em){
			em.parentNode.removeChild(em);
		}
	}
	
	//Function to handle the menu mouseover.
	function menuMouseOver (theObj){
		if (theObj){
			theObj.style.color = "#1671b1";
		}
	}
	
	//Function to handle the menu mouseout.
	function menuMouseOut (theObj){
		if (theObj){
			theObj.style.color = "#333333";
		}
	}
	
	function destroyAllMenus (e){
		if (nowOpenMenus.length == 0){
			//return false;
		} else {
		
			if (!e){
				var e = window.event;
			}
		
			if (e.pageX){
				tempX = e.pageX
			} else if (e.clientX){
				tempX = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
			}
			if (e.pageY){
				tempY = e.pageY
			} else if (e.clientY){
				tempY = e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
			}
			
			tempX = parseInt (tempX);
			tempY = parseInt (tempY);
			
			//Now, loop through the menus and see if the mouse click falls on any of them.
			var kill = true;
			for (var i = 0; i < nowOpenMenus.length; i++){
				
				//Get the menu.
				var tMenu = document.getElementById(nowOpenMenus[i]);
				if (tMenu){
					//Width range.
					var startW = parseInt (tMenu.style.left.replace ("px",""));
					var endW = (startW + parseInt (tMenu.offsetWidth));
					//Height range.
					var startH = (parseInt (tMenu.style.top.replace ("px",""))-40);
					var endH = (startH + parseInt (tMenu.offsetHeight) + 40);
					
					if (((tempX > startW) && (tempX < endW)) && ((tempY > startH) && (tempY < endH))){
						kill = false;
					}
				}
			}
			if (kill){
				for (var i = 0; i < nowOpenMenus.length; i++){
					removeElement (nowOpenMenus[i]);
				}
			}
		}
	}
	
	document.onmousemove = destroyAllMenus;
	
	/*
	//Function to destroy all menus if you click outside of a menu.
	document.onclick = function () {
		//First, check if there are any menus open.
		if (nowOpenMenus.length == 0){
			return false;
		} else {
			//Find your current mouse position.
			var curX = mouseX(event);
			alert (curX);
		}
	}
	*/
