// The following uses DOM and is supported by IE5+ and NS6+

var n_menu = 7; // Number of menus (plus choice 0: home)
var n_opt_arr = [0,3,6,6,3,2,0,0]; // Number of options on each menu

var targ_arr = ["/masters/index.shtml","/masters/timeline.shtml","/masters/wars.shtml","/masters/people.shtml","/masters/gendata.shtml","/masters/background.shtml","/masters/about.shtml","/masters/contact.shtml"];
var starg_arr  = new Array; 
starg_arr[1] = new Array("/masters/politics.shtml", "/masters/foreign.shtml", "/masters/family.shtml");
starg_arr[2] = new Array("/masters/war_j.shtml", "/masters/war_c.shtml", "/masters/war_i.shtml", "/masters/war_c2.shtml", "/masters/war_m.shtml", "/masters/war_o.shtml");
starg_arr[3] = new Array("/masters/cast.shtml", "/masters/marius.shtml", "/masters/sulla.shtml", "/masters/caesar.shtml", "/masters/jugur.shtml", "/masters/mithri.shtml");
starg_arr[4] = new Array("/cgi-bin/igmsrch.cgi/n=rome", "/masters/rome-surname.shtml", "/masters/rome1.shtml");
starg_arr[5] = new Array("/masters/names.shtml", "/masters/dates.shtml");

var text_arr = ["Home", "Timelines", "Wars", "People", "Genealogy", "Background", "About the site", "Contact"];
var stext_arr  = new Array; 
stext_arr[1] = new Array("Politics", "Foreign affairs", "Family life");
stext_arr[2] = new Array("Jugurthan War", "Cimbric Wars", "Italian War", "Civil War", "Mithridatic", "Other wars");
stext_arr[3] = new Array("Full cast", "Marius", "Sulla", "Caesar", "Jugurtha", "Mithridates");
stext_arr[4] = new Array("Search name", "Surnames", "A-Z");
stext_arr[5] = new Array("Names", "Dates");
var ppl = 18; // Number of pixels of space for each submenu line
var ppm = 25; // Number of pixels of space for each main menu item

var cmenu = new Array(); // for the menu names
var csubm = new Array(); // for the submenu names
var dm = new Array();
var am = new Array();
var pm = new Array();
var ds = new Array();
var as = new Array();
var brs = new Array();
var i_show, lastmove;
var i_curr_option, i_curr_menu;

i_show = (n_menu + 1);
lastmove = 0;

for (var i = 0; i <= n_menu; i++) {
	cmenu[i] = ('menu' + i);
	csubm[i] = ('submenu' +i);
	}

function domenu() {
//build the DOM elements for the menu
for (var i = 0; i <=n_menu; i++) {
  dm[i] = document.createElement('div');
  dm[i].className = "title light";
  am[i] = document.createElement('a');
  am[i].id = "amenu"+i+"0";
  am[i].className = "default";
  am[i].href = targ_arr[i];
  am[i].onclick = aopen1;
  am[i].onmouseover = aover1;
  am[i].onmouseout = aout1;
  var aText = document.createTextNode(text_arr[i]);
  am[i].appendChild(aText);  
  dm[i].appendChild(am[i]);
  if (n_opt_arr[i] > 0) {
    pm[i] = document.createElement('img');
    pm[i].alt = "-";
    pm[i].id = "pic"+i;
    pm[i].src = "/masters/closed.gif";
    pm[i].style.width = "15px"; 
    pm[i].style.height = "7px";
    dm[i].appendChild(pm[i]);
	}
  dm[i].id = "menu"+i;
  dm[i].style.top = 75+i*ppm+"px";
  document.getElementById("mainmenu").appendChild(dm[i]);
  if (n_opt_arr[i] > 0) {
    ds[i] = document.createElement('div');
    ds[i].className = "submenu light";
    ds[i].id = "submenu"+i;
    ds[i].style.top = 75+i*ppm+"px";
    ds[i].style.height = n_opt_arr[i]*20+"px";
	as[i] = new Array;
	brs[i] = new Array;
    for (var j = 1; j <=n_opt_arr[i]; j++) {
      as[i][j] = document.createElement('a');
	  brs[i][j] = document.createElement('br')
      as[i][j].id = "amenu"+i+j;
      as[i][j].className = "default";
      as[i][j].href = starg_arr[i][j-1];
      as[i][j].onclick = aopen1;
      as[i][j].onmouseover = aover1;
      as[i][j].onmouseout = aout1;
      var aText = document.createTextNode(stext_arr[i][j-1]);
      as[i][j].appendChild(aText);
      ds[i].appendChild(as[i][j]);
      ds[i].appendChild(brs[i][j]);
     }  
    document.getElementById("mainmenu").appendChild(ds[i]);
    }
  }
}
  
function init_menu(i_menu, i_option) {

//set up the menus appropriate to this page

if (!navigator.DOMCSS2) {return}
//hide alternate menu
document.getElementById("fallback").style.visibility = "hidden";
domenu();

// display sub options in-column
if (n_opt_arr[i_menu] > 0) {
  aopen(i_menu,i_option);
  }
// highlight current page selected
aname = 'amenu' + i_menu + i_option;
document.getElementById(aname).className = "current";
i_curr_option = i_option;
i_curr_menu = i_menu;
}

function init_menu2(i_menu) {
// display sub options in-column
if (i_menu == i_curr_menu && n_opt_arr[i_menu] > 0) {
  aopen(i_menu,i_option);
  }
// highlight current page selected
aname = 'amenu' + i_curr_menu + i_curr_option;
document.getElementById(aname).className = "current";
}

function aover1() {
aover(parseInt(this.id.charAt(5)), parseInt(this.id.charAt(6)));
}

function aover(i_menu, i_option) {
if (i_menu == i_curr_menu) {
  if (i_show != i_curr_menu) {ahide()}
  if (i_option != i_curr_option) { 
    aname = 'amenu' + i_menu + i_option;
    document.getElementById(aname).className = "select";
    }
  }
else {
  ashow(i_menu);
  aname = 'amenu' + i_menu + i_option;
  document.getElementById(aname).className = "select";
  i_show = i_menu;
  }
}

function ashow(i_menu) {
if (i_menu==i_show) return;
ahide();
// put away last one
if (n_opt_arr[i_menu]>0) {
  menu = ('submenu' + i_menu);
  submenu = document.getElementById(menu).style;
  submenu.visibility = "visible";
  pic = ('pic' + i_menu);
  document.images[pic].style.visibility = "hidden";
  }
}

function ahide() {
if (i_show<=n_menu && n_opt_arr[i_show]>0) {
  menu = ('submenu' + i_show);
  submenu = document.getElementById(menu).style;
  submenu.visibility = 'hidden';
  pic = ('pic' + i_show);
  document.images[pic].style.visibility = "visible";
  i_show = n_menu + 1;
  }
}
function aout1(){
aout(parseInt(this.id.charAt(5)), parseInt(this.id.charAt(6)));
}

function aout(i_menu, i_option) {
// reset color on exit, except for current option
if (i_menu == i_curr_menu && i_option==i_curr_option) return;
aname = 'amenu' + i_menu + i_option;
document.getElementById(aname).className = "default";
}

function shift(idshift,imove) {
s = document.getElementById(idshift).style.top;
itop = parseInt(s) + imove;
document.getElementById(idshift).style.top = itop + "px";
}

function shift2(idshift) {
s = document.getElementById(idshift).style.top;
itop = parseInt(s) + 25;
document.getElementById(idshift).style.top = itop + "px";
document.getElementById(idshift).className = "inline";
}

function aopen1(){
aopen(parseInt(this.id.charAt(5)), parseInt(this.id.charAt(6)));
}

function aopen(i_menu, i_option) {

imove = n_opt_arr[i_menu];
//i_menu - menu number to open, 
//imove - no. of submenu options for this menu
if (i_menu == i_curr_menu) return;
move = imove * ppl + 6;
if (imove>0) {
// if imove=0, there is no submenu
  menu = ('submenu' + i_menu);
  submenu = document.getElementById(menu).style;
  submenu.visibility = 'visible';
  shift2(menu);

  for (var i = (i_menu+1); i <= n_menu; i++) {
    shift(cmenu[i],move);
    if (n_opt_arr[i]>0) {shift(csubm[i],move)};
    }
  pic = ('pic' + i_menu);
  document.images[pic].style.visibility = "hidden";
  }
}

function printVer() {

if (document.getElementById("mainmenu").style.display == "none") {
  document.getElementById("main1").style.overflow = "auto";
  document.getElementById("mainmenu").style.display = "";
  document.getElementById("pow").style.display = "";
  document.getElementById("vhtml").style.display = "";
  document.getElementById("ptop1").style.display = "";
  document.getElementById("main1").style.position = "relative";
  document.getElementById("main1").style.left = "0";
  document.getElementById("main1").style.top = "0";
  document.getElementById("ptoggle").innerText = "Printable version";
  }
else {
  document.getElementById("main1").style.overflow = "visible";
  document.getElementById("mainmenu").style.display = "none";
  document.getElementById("pow").style.display = "none";
  document.getElementById("vhtml").style.display = "none";
  document.getElementById("ptop1").style.display = "none";
  document.getElementById("main1").style.position = "relative";
  document.getElementById("main1").style.left = "-120";
  document.getElementById("main1").style.top = "0";
  document.getElementById("ptoggle").innerText = "Normal layout";
  }

 }
