
	//Global array to track what menus are currently open.
	var nowOpenMenus = Array();
	var openMenuCount = 0;
	
	//Mouse positions.
	var tempX = 0;
	var tempY = 0;
	
  //kt 2011 Aug28	
	function popMenuWBuy(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_short";
			newMenu.id = menuId;
			
			//Add to the list of open menus.
			nowOpenMenus[openMenuCount] = menuId;
			openMenuCount++;
			
			var endHTML = "<div class=\"pop_up_menu_top_short\"></div>";
			endHTML += "<div class=\"pop_up_menu_middle_short\">";
			endHTML += "<div class=\"pop_up_menu_middle_pad\">";
			
			//Build the array of menu items.
			var count = 0;
			endHTML += "<table style=\"width: 100%; border: none;\" cellpadding=\"2\" cellspacing=\"0\">";
			for (var i = 0; i < theMenu.length; i++){
			
				if (count <= 27){
			
					if (count == 0){
					
						endHTML += "<tr>";
						endHTML += "<td style=\"width: 33%; vertical-align: top;\" class=\"menu_td_div_line\">";
					
					}
					
					if ((count % 9) == 0){
					
						if (count != 0){
					
							endHTML += "</td>";
							
							if (count == 9){
							
								endHTML += "<td style=\"width: 33%; vertical-align: top;\" class=\"menu_td_div_line\">";
								
							} else {
							
								endHTML += "<td style=\"width: 33%; vertical-align: top;\">";
							
							}
							
						}
						
					}
				
					//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";
					}
					
					var link = splitMenu[4];
					
					if ( splitMenu[4] != "null"){
  					if ( link.substring(0,4) == "www." ) {
						  endHTML += "<div class=\"menu_item\"><a href=http://"+splitMenu[4]+" target=_blank onclick=\"closeMenus ();\" class=\"footer_menu\">";
            }
            else
						  endHTML += "<div class=\"menu_item\"><a href=\""+splitMenu[4]+"\" onclick=\"closeMenus ();\" class=\"footer_menu\">";
					} else { 
						endHTML += "";
					}
					endHTML += splitMenu[0];
					
					endHTML += "</a></div>";
					
					count++;
					
				}
			}
			endHTML += "</td></tr>";
			endHTML += "</table>";
			
			endHTML += "</div></div>";
			endHTML += "<div class=\"pop_up_menu_bottom_short\"></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);
				}
			}

			newMenu.style.top = "212px";
			newMenu.style.left = (x-2)+"px";
			
			document.body.appendChild (newMenu);
		}
  }
  	
	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\">";
			endHTML += "<div class=\"pop_up_menu_middle_pad\">";
			
			//Build the array of menu items.
			var count = 0;
			endHTML += "<table style=\"width: 100%; border: none;\" cellpadding=\"2\" cellspacing=\"0\">";
			for (var i = 0; i < theMenu.length; i++){
			
				if (count <= 37){
			
					if (count == 0){
					
						endHTML += "<tr>";
						endHTML += "<td style=\"width: 200px; vertical-align: top;\" class=\"menu_td_div_line\">";
					
					}
					
					if ((count % 9) == 0){
					
						if (count != 0){
					
							endHTML += "</td>";
							
							if (count == 9){
							
								endHTML += "<td style=\"width: 200px; vertical-align: top;\" class=\"menu_td_div_line\">";
								
							} else {
							
								endHTML += "<td style=\"width: 200px; vertical-align: top;\" class=\"menu_td_div_line\">";
							
							}
							
						}
						
					}
				
					//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[4] != "null"){
						endHTML += "<div class=\"menu_item\"><a href=\""+splitMenu[4]+"\" onclick=\"closeMenus ();\" class=\"footer_menu\">";
					} else {
						endHTML += "";
					}
					endHTML += splitMenu[0];
					
					endHTML += "</a></div>";
					
					count++;
					
				}
			}
			endHTML += "</td></tr>";
			endHTML += "</table>";
			
			endHTML += "</div></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);
				}
			}

			newMenu.style.top = "212px";
			newMenu.style.left = (x-2)+"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",""))-55);
					var endH = (startH + parseInt (tMenu.offsetHeight) + 55);
					
					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);
		}
	}
	*/
