////////////////////////////////////////////
// This document contains all the code for controlling the menu system,
// including the menus on the top and on the left side of the site

// Function getCookie
// Original JavaScript code by Duncan Crombie: dcrombie at chirp.com.au
// Please acknowledge use of this code by including this header.

var bikky = document.cookie;

function getCookie(name) {
name += "="; // append '=' to name string
var i = 0; // index of first name=value pair
while (i < bikky.length) {
  var offset = i + name.length; // end of section to compare with name string
  if (bikky.substring(i, offset) == name) { // if string matches
    var endstr = bikky.indexOf(";", offset); // locate end of name=value pair
    if (endstr == -1) endstr = bikky.length;
    return unescape(bikky.substring(offset, endstr)); // return cookie value section
  }
  i = bikky.indexOf(" ", i) + 1; // move i to next name=value pair
  if (i == 0) break; // no more values in cookie string
}
return null; // cookie not found
}

// Preload the appropriate menu images
var arImages=new Array();
var imageList = new Array(
	'http://images.vendetta-online.com/images/page_main_01.gif',
	'http://images.vendetta-online.com/images/page_main_02.jpg',
	'http://images.vendetta-online.com/images/page_main_03.gif',
	'http://images.vendetta-online.com/images/page_main_04.gif',
	'http://images.vendetta-online.com/images/page_main_06.gif',
	'http://images.vendetta-online.com/images/page_main_10.gif',
	'http://images.vendetta-online.com/images/page_main_11.gif',
	'http://images.vendetta-online.com/images/page_main_12.gif',
	'http://images.vendetta-online.com/images/page_left_head.gif',
	'http://images.vendetta-online.com/images/page_left_body.jpg',
	'http://images.vendetta-online.com/images/page_left_body2.jpg',
	'http://images.vendetta-online.com/images/page_left_foot.gif');

var LoggedIn = getCookie("session") || 0;
if (LoggedIn == 0) { 
	imageList[imageList.length] = "http://images.vendetta-online.com/images/page_top.jpg"; 
} 

function Preload() {
 for(x=0; x < imageList.length; x++) {
  arImages[x]=new Image();
  arImages[x].src=imageList[x];
 }
}

// Display the appropriate menu on the top of the page, based on whether
// the user is logged in or not
function menu_top() {
	if (LoggedIn == 0) { menu_top_notloggedin(); } 
	else { menu_top_loggedin(); }
}

// Display the not-logged-in version of the menu
function menu_top_notloggedin() {
	document.write(
	"<center>\n"+
	"<div class=topbar>\n");

    b1_off = new Image();
    b1_off.src = "http://images.vendetta-online.com/images/page_top_b1off.jpg";

    b2_off = new Image();
    b2_off.src = "http://images.vendetta-online.com/images/page_top_b2off.jpg";

    b3_off = new Image();
    b3_off.src = "http://images.vendetta-online.com/images/page_top_b3off.jpg";

    b1_on = new Image();
    b1_on.src = "http://images.vendetta-online.com/images/page_top_b1on.jpg";

    b2_on = new Image();
    b2_on.src = "http://images.vendetta-online.com/images/page_top_b2on.jpg";

    b3_on = new Image();
    b3_on.src = "http://images.vendetta-online.com/images/page_top_b3on.jpg";

	document.write(
	"<a href=/h/help.html onmouseover=\"b1.src = b1_on.src;\" onmouseout=\"b1.src = b1_off.src;\" style=\"position:relative;left:178px;top:147px;\"><img src=http://images.vendetta-online.com/images/page_top_b1off.jpg name=b1 border=0 width=134 height=40></a>\n"+
	"<a href=https://www.vendetta-online.com/x/newacct onmouseover=\"b2.src = b2_on.src;\" onmouseout=\"b2.src = b2_off.src;\" style=\"position:relative;left:174px;top:147px;\"><img src=http://images.vendetta-online.com/images/page_top_b2off.jpg name=b2 border=0 width=116 height=40></a>\n"+
	"<a href=/h/screenshots.html onmouseover=\"b3.src = b3_on.src;\" onmouseout=\"b3.src = b3_off.src;\" style=\"position:relative;left:170px;top:147px;\"><img src=http://images.vendetta-online.com/images/page_top_b3off.jpg name=b3 border=0 width=136 height=40></a>\n"+
	"</div>\n"+
	"</center>\n");
}

// Display the logged-in version of the menu
function menu_top_loggedin() {
	document.write(
	"<center>\n"+
	"<img src=http://images.vendetta-online.com/images/page_top_loggedin.jpg width=760 height=120>\n"+
	"</center>\n");
}

// Display the appropriate menu on the left side of the page, based on whether
// the user is logged in or not
function menu_left() {
	if (LoggedIn == 0) { menu_left_notloggedin(); } 
	else { menu_left_loggedin(); }
}
// Display the not-logged-in version of the menu
function menu_left_notloggedin() {
	var param=window.location.pathname.substring(3)

	document.write(
	"<div class=menutitle>Web</div>\n"+
	"<div class=submenu>\n"+
	"	<a class=menu href=/h/welcome.html>Welcome!</a><br>\n"+
	"	<a class=menu href=https://www.vendetta-online.com/x/newacct>New Account</a><br>\n"+
	"	<a class=menu href=https://www.vendetta-online.com/x/login>Login</a><br>\n"+
	"</div>\n"+
	"<div class=menutitle>About Vendetta</div>\n"+
	"<div class=submenu>\n"+
	"	<a class=menu href=/h/help.html>Introduction</a><br>\n"+
	"	<a class=menu href=/h/news.html>News</a><br>\n"+
	"	<a class=menu href=/manual.html>Manual</a><br>\n"+
	"	<a class=menu href=/h/faq.html>FAQ</a><br>\n");

	// Display the FAQ sub-menu if necessary
	var action = param.substring(0,3)

	if (action == "faq") { 
		document.write(
		"<div class=submenu2>\n"+
		"	<a class=menu href=/h/faq_general.html>General</a><br>\n"+
		"	<a class=menu href=/h/faq_tech.html>Technical</a><br>\n"+
		"	<a class=menu href=/h/faq_gameplay.html>Gameplay</a><br>\n"+
		"	<a class=menu href=/h/faq_community.html>Community</a><br>\n"+
		"</div>\n");
	}

	// Get back to work with the normal menu
//	document.write(
//	"	<a class=menu href=/manual/ target=new>Manual</a><br>\n"+
//	"	<a class=menu href=/h/universe.html>Vendetta Universe</a><br>\n");

	// Display the Vendetta Universe sub-menu if necessary
//	action = param.substring(0,8)

//	if (action == "universe") { 
//		document.write(
//		"<div class=submenu2>\n"+
//		"	<a class=menu href=/h/universe_general.html>General</a><br>\n"+
//		"	<a class=menu href=/h/universe_history.html>History</a><br>\n"+
//		"	<a class=menu href=/h/universe_combat.html>Flight & Combat</a><br>\n"+
//		"	<a class=menu href=/h/universe_navigation.html>The Universe</a><br>\n"+
//		"	<a class=menu href=/h/universe_ships.html>Ships</a><br>\n"+
//		"</div>\n");
//	}

	document.write(
	"	<a class=menu href=/h/storyline.html>Backstory</a><br>\n");
	action = param.substring(0,9)
	if (action == "storyline") {
		document.write(
		"<div class=submenu2>\n"+
		"	<a class=menu href=/h/storyline_section2.html>Section II</a><br>\n"+
		"	<a class=menu href=/h/storyline_section3.html>Section III</a><br>\n"+
		"	<a class=menu href=/h/storyline_section4.html>Section IV</a><br>\n"+
		"	<a class=menu href=/h/storyline_section5.html>Section V</a><br>\n"+
		"	<a class=menu href=/h/storyline_section6.html>Section VI</a><br>\n"+
		"	<a class=menu href=/h/storyline_section7.html>Section VII</a><br>\n"+
		"	<a class=menu href=/h/storyline_section8.html>Section VIII</a><br>\n"+
		"	<a class=menu href=/h/storyline_section9.html>Section IX</a><br>\n"+
		"	<a class=menu href=/h/storyline_section10.html>Section X</a><br>\n"+
		"	<a class=menu href=/h/storyline_section11.html>Section XI</a><br>\n"+
		"	<a class=menu href=/h/storyline_section12.html>Section XII</a><br>\n"+
		"</div>\n");
	}

	// Get back to work with the normal menu
	document.write(
	"	<a class=menu href=/h/screenshots.html>Screenshots</a><br>\n"+
	"</div>\n"+
	"<div class=menutitle>Community</div>\n"+
	"<div class=submenu>\n"+
	"	<a class=menu href=http://merch.vendetta-online.com>Merchandise</a><br>\n"+
	"	<a class=menu href=/x/msgboard>Message Board</a><BR>\n"+
	"       <a class=menu href=/x/pcc>Player Contribution Corps</a><BR>\n"+
	"	<a class=menu href=/h/links.html>Community Sites</a><BR>\n"+
	"</div>\n"+
	"<BR>\n"+
	"<center>\n")
	sotd()
	document.write("<a class=menutitle href=/h/screenshots.html>Featured Screenshot</a><BR>\n"+
	"</center>");
}

// Display the logged-in version of the menu
function menu_left_loggedin() {
	var param=window.location.pathname.substring(3)

	document.write(
	"<div class=menutitle>About Vendetta</div>\n"+
	"<div class=submenu>\n"+
	"	<a class=menu href=/h/help.html>Introduction</a><br>\n"+
	"	<a class=menu href=/h/news.html>News</a><BR>\n"+
	"	<a class=menu href=/manual.html>Manual</a><br>\n"+
	"	<a class=menu href=/h/work.html>In Progress</a><BR>\n"+
	"	<a class=menu href=/h/faq.html>FAQ</a><br>\n");

	// Display the FAQ sub-menu if necessary
	var action = param.substring(0,3)

	if (action == "faq") { 
		document.write(
		"<div class=submenu2>\n"+
		"	<a class=menu href=/h/faq_general.html>General</a><br>\n"+
		"	<a class=menu href=/h/faq_tech.html>Technical</a><br>\n"+
		"	<a class=menu href=/h/faq_gameplay.html>Gameplay</a><br>\n"+
		"	<a class=menu href=/h/faq_community.html>Community</a><br>\n"+
		"</div>\n");
	}

	// Get back to work with the normal menu
//	document.write(
//	"	<a class=menu href=/manual/ target=new>Manual</a><br>\n"+
//	"	<a class=menu href=/h/universe.html>Vendetta Universe</a><br>\n");

	// Display the Vendetta Universe sub-menu if necessary
//	action = param.substring(0,8)

//	if (action == "universe") { 
//		document.write(
//		"<div class=submenu2>\n"+
//		"	<a class=menu href=/h/universe_general.html>General</a><br>\n"+
//		"	<a class=menu href=/h/universe_history.html>History</a><br>\n"+
//		"	<a class=menu href=/h/universe_combat.html>Flight & Combat</a><br>\n"+
//		"	<a class=menu href=/h/universe_navigation.html>The Universe</a><br>\n"+
//		"	<a class=menu href=/h/universe_ships.html>Ships</a><br>\n"+
//		"</div>\n");
//	}

	document.write(
	"	<a class=menu href=/h/storyline.html>Backstory</a><br>\n");
	action = param.substring(0,9)
	if (action == "storyline") {
		document.write(
		"<div class=submenu2>\n"+
		"	<a class=menu href=/h/storyline_section2.html>Section II</a><br>\n"+
		"	<a class=menu href=/h/storyline_section3.html>Section III</a><br>\n"+
		"	<a class=menu href=/h/storyline_section4.html>Section IV</a><br>\n"+
		"	<a class=menu href=/h/storyline_section5.html>Section V</a><br>\n"+
		"	<a class=menu href=/h/storyline_section6.html>Section VI</a><br>\n"+
		"	<a class=menu href=/h/storyline_section7.html>Section VII</a><br>\n"+
		"	<a class=menu href=/h/storyline_section8.html>Section VIII</a><br>\n"+
		"	<a class=menu href=/h/storyline_section9.html>Section IX</a><br>\n"+
		"	<a class=menu href=/h/storyline_section10.html>Section X</a><br>\n"+
		"	<a class=menu href=/h/storyline_section11.html>Section XI</a><br>\n"+
		"	<a class=menu href=/h/storyline_section12.html>Section XII</a><br>\n"+
		"</div>\n");
	}

	// Get back to work with the normal menu
	document.write(
	"	<a class=menu href=/h/screenshots.html>Screenshots</a><br>\n"+
	"</div>\n"+
	"<div class=menutitle>Game</div>\n"+
	"<div class=submenu>\n"+
	"	<a class=menu href=/x/download>Download</a><br>\n"+
	"	<a class=menu href=/x/stats>Your Stats</a><br>\n"+
	"	<a class=menu href=/x/active>Active Players</a><br>\n"+
	"	<a class=menu href=/h/cargostats.html>Cargo Captures</a><br>\n"+
	"	<a class=menu href=/h/duelstats/page1.html>Duel Stats</a><br>\n"+
	"	<a class=menu href=/x/racestats>Race Stats</a><br>\n"+
	"	<a class=menu href=/x/events>Event Submissions</a><br>\n"+
	"</div>\n"+
	"<div class=menutitle>Your Account</div>\n"+
	"<div class=submenu>\n"+
	"	<a class=menu href=https://www.vendetta-online.com/x/support>Customer Support</a><br>\n"+
	"	<a class=menu href=https://www.vendetta-online.com/x/changeacct>Account Info</a><br>\n"+
	"	<a class=menu href=https://www.vendetta-online.com/x/payoptions>Billing Options</a><br>\n"+
	"	<a class=menu href=https://www.vendetta-online.com/h/eula.html>Licensing Agreement</a><br>\n"+
	"	<a class=menu href=https://www.vendetta-online.com/h/conduct.html>Rules of Conduct</a><br>\n"+
	"	<a class=menu href=https://www.vendetta-online.com/x/changepass>Password</a><br>\n"+
	"	<a class=menu href=/x/logout>Log Out</a>\n"+
	"</div>\n"+
	"<div class=menutitle>Community</div>\n"+
	"<div class=submenu>\n"+
	"	<a class=menu href=http://merch.vendetta-online.com>Merchandise</a><br>\n"+
	"	<a class=menu href=/x/msgboard?agree=y>Message Board</a><BR>\n"+
	"	<a class=menu href=/x/pcc>Player Contribution Corps</a><BR>\n"+
	"	<a class=menu href=/h/links.html>Community Sites</a><BR>\n"+
	"	<a class=menu href=/x/guildinfo>Player Guilds</a><BR>\n"+
	"</div>\n"+
	"<BR>\n"+
	"<center>\n")
	sotd()
	document.write("<a class=menutitle href=/h/screenshots.html>Featured Screenshot</a><BR>\n"+
	"</center>");
}

