var m_MenuSelected = 0;
var m_ItemSelected = 0;
var m_ItemTimerId = 0;
var m_MenuVisited = false;
var m_URL_Logout = new String(document.location);

if (m_URL_Logout.indexOf("/logout.axd",1) == -1)
   {
      
   if (m_URL_Logout.indexOf("?",1) == -1)
      {
      m_URL_Logout = m_URL_Logout + '/logout.axd';
      }
   else
      {
      if (m_URL_Logout.indexOf("?",1) + 1 == m_URL_Logout.length)
         {
         // ? is the last character
         m_URL_Logout = m_URL_Logout + '/logout.axd';
         }
      else
         {
         m_URL_Logout = m_URL_Logout + '/logout.axd';
         }
      }
   }



//type "[sub]" followed by the title text to indicate that this item should be submenu item.
//type "----" to indicate a horizontal line break.

var m_MenuItems = new Array(
	['Home',				               m_WebPath + "index.aspx",			                     "m6.gif",
		["GalCiv II Website",		   "http://www.galciv2.com",	                           "Access The Official Galactic Civilizations II Website."],
		["Metaverse Home",		      m_WebPath + "index.aspx",				                              "Returns To The Galactic Metaverse Home Page."],
		["Forums",		               "http://forums.galciv2.com",				               "Interact With Other Fans On The Forums."],
		["Journals",		            "http://www.galciv2.com/journals.aspx",				   "Read The Latest Developer Journals."]
	],

	['High Scores',				      m_WebPath + "index.aspx?g=topscores&m=0",			      "m1.gif",
		["Game Stats",				      m_WebPath + "index.aspx?g=topscores&m=0",	            "View Game High Scores"],
		/* ["[sub]Top Characters",		m_WebPath + "index.aspx?g=topchars&m=0",				   "View Game High Scores For Top Charecters"], */
		/* ["[sub]Top Empires",		   m_WebPath + "index.aspx?g=topempires&m=0",			   "View Game High Scores For Top Empires"], */
		["Forum Stats",				   m_WebPath + "index.aspx?g=topscores&m=1",			      "View Forum High Scores"], /*,*/
		/* ["[sub]Top Authors",		   m_WebPath + "index.aspx?g=topauthors&m=1",			   "View Forum High Scores For Top Authors"], */
		/* ["[sub]Top Commenters",		m_WebPath + "index.aspx?g=topcomm&m=1",				   "View Forum High Scores For Top Commenters"] */
		["Galactic Map",				   m_WebPath + "index.aspx?g=map",	            "Galactic Map"]
		

	],
	['Galactic Databank',			   "http://www.galciv2.com/Databanks.aspx",				   "m2.gif",
	   ["Downloads",				      "http://www.galciv2.com/Downloads.aspx",		         "Access Exciting Downloads"],
	   ["----",				            "",         									               ""],
	   ["Civilizations",				   "http://www.galciv2.com/Databank/civs.aspx",		      "Explore Strange New Worlds. To Seek Out New Life And Civilizations. To Boldly Go Where No One Has Gone Before."],
		["Fan Sites",			         m_WebPath + "index.aspx?g=fansites",				      "Fan Sites"],   
		["FAQ",				            "http://www.galciv2.com/Databank/faq.aspx",			   "Frequently Asked Questions"],
		["Information Guide",			"http://www.galciv2.com/infoguide.aspx",				   "Information Guide"],	   
		["Legend",				         m_WebPath + "index.aspx?g=legend",				         "Learn More About The Many Details Of The Meteverse"],	   
		["Modding Guide",		         "http://galciv.wikicities.com/wiki/Category:Mods",		"Learn to make  your own mods"],	   
	   ["Our Story So Far...",			"http://www.galciv2.com/story.aspx",					   "Our Story So Far..."],
	   ["Screen Shots",				   "http://www.galciv2.com/Databank/civs.aspx",		      "View The Latest Screen Shots."],
	   ["Strategy Guide",			   "http://www.galciv2.com/Journals.aspx?AID=104908",    "Learn how to conquer the galaxy."],
		["Tech Tree",			         m_WebPath + "index.aspx?g=techtree",				      "Your quick guide to GalCivII Research"]
		/* ["Battle Simulator",	         m_WebPath + "index.aspx?g=battlesim",			      "Find out how your ship will fare with our Battle Simulator"],  */
		

	],
   ['Galactic Library',					"http://library.galciv2.com/",     "m5.gif", 
	   ["Add/Upload New Mods",				"http://library.galciv2.com/index.aspx?g=add",		"Add/Upload New Mods"],
	   ["----",				            "",         									               ""],
		["Anomalies",					   "http://library.galciv2.com/index.aspx?c=1",			"Anomalies"],
		["Campaigns",					   "http://library.galciv2.com/index.aspx?c=2",			"Campaigns"],
		["Events",					      "http://library.galciv2.com/index.aspx?c=3",			"Events"],
		["Improvements",					"http://library.galciv2.com/index.aspx?c=4",			"Improvements"],
		["Maps",					         "http://library.galciv2.com/index.aspx?c=5",			"Maps"],
		["Misc",					         "http://library.galciv2.com/index.aspx?c=6",			"Misc"],
		["Race Logos",					   "http://library.galciv2.com/index.aspx?c=13",		"Race Logos"],
		["Scenarios",					   "http://library.galciv2.com/index.aspx?c=7",			"Scenarios"],
		["Ships",					      "http://library.galciv2.com/index.aspx?c=8",			"Ships"],
		["Technologies",					"http://library.galciv2.com/index.aspx?c=9",			"Technologies"],
		["United Planets",				"http://library.galciv2.com/index.aspx?c=10",		"United Planets"],
		["Screenshots",				   "http://library.galciv2.com/index.aspx?c=12",		"Screenshots"],
		["Ship Components",				"http://library.galciv2.com/index.aspx?c=11",		"Ship Components"]
	


	],
	['Account',					         "http://www.galciv2.com/MyAccount.aspx",	            "m3.gif", 
		["Create Account",	         m_WebPath + "index.aspx?g=createaccount",					"Create A Stardock.net Account"],
		["Log Off",				         m_URL_Logout,						                        "Log Off The Website"],
		["View My Profile",	         m_WebPath + "index.aspx?g=sdnetaccount",					"View My Profile"],
		["View My Empire",	         m_WebPath + "index.aspx?g=myempire",					   "View My Empire"],
		["----",				            "",         									               ""],
		["Edit My Characters",	      m_WebPath + "index.aspx?g=managecharacters",			   "Edit My Character Information"],
		["Edit My Empire",	         m_WebPath + "index.aspx?g=manageempire",              "Edit My Empire Information"],
		["Manage My Account",			"http://www.galciv2.com/MyAccount.aspx",  "Manage My Account"],
		["Character Watchlist",			m_WebPath + "index.aspx?g=watch",  "Characters I am Watching"]
	],
	['Store',					         "http://www.galciv2.com/purchase.aspx?game=galciv2",	"m4.gif", 
		["",					            "",										                       ""]
	]
	
	);

	
function iSelect(item, mode)
{
	if(mode==0){
		item.className='Icon_Selected';
		m_ItemSelected = 1;
	}else{
		item.className='Icon';
		m_ItemSelected = 0;
	}
}
function hideRegisteredInputItems(mode)
{
   var obj = document.getElementsByTagName('SELECT');
   var _str = "";
   for(var i=0; i<obj.length; i++){
      //Registered Sex Offenders...
      if(obj[i].name=='search'||obj[i].name=='_PageControl$_CategoryList'||obj[i].name=='_SortList'){
         _str = obj[i].className;
         
         //Strip out Hide, Show, Invisible, Visible from className first.
         _str = _str.replace(/Hide/g, "");
         _str = _str.replace(/Show/g, "");
         _str = _str.replace(/Invisible/g, "");
         _str = _str.replace(/Visible/g, "");
          
         if(mode==1){
              _str = _str + ' Invisible';
         }
         obj[i].className=_str
      }
   }
}
function divSelect(item, mode)
{
   
   
	if(m_MenuSelected != item.id && m_MenuSelected != 0 && item.id != 0){ 
		document.getElementById(m_MenuSelected).className='Out';
		document.getElementById(m_MenuSelected + '_sub').className='Hide'; 
	}
	if(mode==0){
		item.className='Over';
		document.getElementById(item.id + '_sub').className='SubDropdown Show';
		m_MenuSelected = item.id;			
		clearTimeout(m_ItemTimerId);
		m_ItemTimerId = 0;
	}else{
		if(m_ItemSelected == 0 && m_ItemTimerId == 0){
			m_ItemTimerId = setTimeout("hideMenu('" + m_MenuSelected + "')", 1000);
		}
	}
	if(document.getElementById(m_MenuSelected + '_sub').scrollHeight>=35){
      hideRegisteredInputItems(1);
   }else{
      hideRegisteredInputItems(0);
   }
}
function hideMenu(item)
{
	if(m_ItemSelected == 0){
		document.getElementById(item).className='Out';
		document.getElementById(item + '_sub').className='Hide';
		clearTimeout(m_ItemTimerId);
		m_ItemTimerId = 0;
		hideRegisteredInputItems(0);
	}else{
	   
		clearTimeout(m_ItemTimerId);
		m_ItemTimerId = setTimeout("hideMenu('" + item + "')", 10);
	}
}
function drawMenu(id)
{
	var div = document.getElementById(id);
	var str = '';
	str += '<table cellpadding=0 cellspacing=0 border=0 align=left>';
	str += '<tr>';
	for(var i = 0; i < m_MenuItems.length; i++){
		str += '<td>';
			str += '<div class="Out" ';
			str += 'onMouseOver="divSelect(this,0);" ';
			str += 'onMouseOut="divSelect(this,1);" ';
			if(m_MenuItems[i][1].toString!=''){ 
				str += 'onclick="redirectFromMenu(\'' + m_MenuItems[i][1]  + '\',0);" '; 
			}
			str += 'id="itemMenu'+ i +'" ';
			str += '>';
				if (m_MenuItems[i].length > 1){
					str += '<div ';
					str += 'class="SubDropdown Hide" '
					if(m_MenuItems[i][3][0].length==0){	//Hides the empty ddl menu off the screen.
						str += 'style="left:-1000px; top: -1000px; position:absolute;"' 
					} 
					str += 'id="itemMenu' + i + '_sub" ';
					str += '>';
						str += '<table cellpadding=0 cellspacing=0>';
						str += '<tr>';
							str += '<td width=4 height=4 background="' + m_ImagePath + 'submenu-t-l.gif"><img src="' + m_ImagePath + 'spacer.gif"></td>';
							str += '<td height=4 background="' + m_ImagePath + 'submenu-t-bg.gif"><img src="' + m_ImagePath + 'spacer.gif"></td>';
							str += '<td width=4 height=4><img src="' + m_ImagePath + 'submenu-t-r.gif"></td>';
						str += '</tr>';
						str += '<tr>';
							str += '<td width=4 background="' + m_ImagePath + 'submenu-l-bg.gif"><img src="' + m_ImagePath + 'spacer.gif"></td>';
							str += '<td valign=top background="' + m_ImagePath + 'submenu-bg.gif">';
								str += '<div class="SubDropdownPadding">'
								for(var ii = 3; ii < m_MenuItems[i].length; ii++){
							      if(m_MenuItems[i][ii][0].indexOf('----')>=0){
							         str += '<div class="SubMenuItemDivider"><img src="' + m_ImagePath + 'spacer.gif" height=1 width=1></div>';	
							      }else if(m_MenuItems[i][ii][0].indexOf('[sub]')>=0){
							         str += '<div class="SubMenuItem_Sub SubOut_Sub" ';
								      if(m_MenuItems[i][1].length!=0){ 
								         //str += 'onmouseover="this.className=\'SubMenuItem_Sub SubOver\';window.status=\'' + m_MenuItems[i][ii][2] + '\';return true;" ';
								         str += 'onmouseover="this.className=\'SubMenuItem_Sub SubOver\';return true;" ';
								         //str += 'onmouseout="this.className=\'SubMenuItem_Sub SubOut_Sub\';window.status=\'\';" ';
								         str += 'onmouseout="this.className=\'SubMenuItem_Sub SubOut_Sub\';" ';
									      str += 'onclick="redirectFromMenu(\'' + m_MenuItems[i][ii][1]  + '\',1);" ';
									      str += 'title="' + m_MenuItems[i][ii][2] + '" ';
								      }else{
								         str += 'onclick="redirectFromMenu(\'#\',1);" ';
								      }
								      str += '>';
								      str += m_MenuItems[i][ii][0].substring(5,m_MenuItems[i][ii][0].length);
								      str += '</div>';
							      }else{
							         if(m_MenuItems[i][ii][0].indexOf('Log Off')>=0&&getCookie("AuthCookie2")==null){
							         }else if(m_MenuItems[i][ii][0].indexOf('Create Account')>=0&&getCookie("AuthCookie2")!=null){
							         }else{
							            str += '<div class="SubMenuItem SubOut" ';
								         if(m_MenuItems[i][1].length!=0){ 
								            //str += 'onmouseover="this.className=\'SubMenuItem SubOver\';window.status=\'' + m_MenuItems[i][ii][2] + '\';return true;" ';
								            str += 'onmouseover="this.className=\'SubMenuItem SubOver\';return true;" ';
								            //str += 'onmouseout="this.className=\'SubMenuItem SubOut\';window.status=\'\';" ';
								            str += 'onmouseout="this.className=\'SubMenuItem SubOut\';" ';
									         str += 'onclick="redirectFromMenu(\'' + m_MenuItems[i][ii][1]  + '\',1);" ';
									         str += 'title="' + m_MenuItems[i][ii][2] + '" ';
								         }else{
								            str += 'onclick="redirectFromMenu(\'#\',1);" ';
								         }
								         str += '>';
								         str += m_MenuItems[i][ii][0];
								         str += '</div>';	
								      }
							      }
								}
								str += '</div>';
							str += '</td>';
							str += '<td width=4 background="' + m_ImagePath + 'submenu-r-bg.gif"><img src="' + m_ImagePath + 'spacer.gif"></td>';
						str += '</tr>';
						str += '<tr>';
							str += '<td width=4 height=4><img src="' + m_ImagePath + 'submenu-b-l.gif"></td>';
							str += '<td height=4 background="' + m_ImagePath + 'submenu-b-bg.gif"><img src="' + m_ImagePath + 'spacer.gif"></td>';
							str += '<td width=4 height=4><img src="' + m_ImagePath + 'submenu-b-r.gif"></td>';
						str += '</tr>';
						str += '</table>';
					str += '</div>';
				}
				str += '<img src="' + m_ImagePath + m_MenuItems[i][2] + '" border=0>';
				str += ' ';
				str += m_MenuItems[i][0];
			str += '</div>';
		str += '</td>';
	}
	str += '</tr>';
	str += '</table>';
	div.innerHTML = str;
}
function redirectFromMenu(link,type)
{
	if(type==1){
		location.href=link;
		m_MenuVisited = true
	}else if(type==0 && m_MenuVisited!=true){
		location.href=link;
	}
}
