////////////////////////////////////////////////
//    ___            _ ____  ___              //
//   / _ | ___ _  __(_) /  |/  /__ ___ __ __  //
//  / __ |/ _ \ |/ / / / /|_/ / -_) _ Y // /  //
// /_/ |_/_//_/___/_/_/_/  /_/\__/_//_|_,_/   //
//                                            //
////////////////////////////////////////////////

// DOM Menu System v1.0 12/2001
// Works on Gecko and IE5+ browsers
// Designed by anvilSoup <echan101@hotmail.com>
// Use under GPL (http://www.gnu.org/)
// Designed for http://earth.prohosting.com/anvils

var activeMenu = -1;
var holdMenu = 0;
var fired = 0;
var menuName = new Array();
var preloadImage = new Array();

function Menu(name, iconName, iconLink, positionYIcon, positionYMenu) {
  // Variables
  this.menuItem  = new Array();
  this.menuLink  = new Array();
  this.name      = name;
  this.iconName  = iconName;
  this.iconLink  = iconLink;
  this.positionYIcon = positionYIcon;
  this.positionYMenu = positionYMenu;
  
  // Methods
  this.addMenuItem = addMenuItem;
  this.createMenu  =  createMenu;
}

function show (e) {
  if (is_ie4up) icon = window.event.srcElement;
  if (is_gecko) icon = e.target;
  menuItem = document.getElementById(icon.id+"Item");
  icon.src = "../" + icon.id + "_on.gif";
  if (activeMenu != -1) hidePreviousMenu();
  menuItem.style.visibility = "visible";
  activeMenu = menuItem;
}

function hide (e) {
  if (is_ie4up) icon = window.event.srcElement;
  if (is_gecko) icon = e.target;
  menuItem = document.getElementById(icon.id+"Item");
  icon.src = "../" + icon.id + "_off.gif";
  holdMenu = setTimeout("menuItem.style.visibility = 'hidden'", 500);
}

function holdItem (e) {
  clearTimeout(holdMenu);
}

function releaseItem (e) {
  if (is_ie4up) menuItem = window.event.srcElement;
  if (is_gecko) menuItem = e.target;
  icon = document.getElementById(menuItem.id.substring(0,menuItem.id.length-4));
  holdMenu = setTimeout("hidePreviousMenu()", 500);
}

function hidePreviousMenu () {
  activeMenu.style.visibility = "hidden";
  clearTimeout(holdMenu);
  activeMenu = -1;
}

function addMenuItem (label, url) {
  this.menuItem[this.menuItem.length] = label;
  if (window.location.toString().indexOf("anvils")==-1) {
    url = "http://earth.prohosting.com/anvils/" + url.substring(2,url.length);
  }
  this.menuLink[this.menuLink.length] = url;
}

function highlight (howDoesGeckoHandleEvents) {
  if (is_ie4up) menuItem = window.event.srcElement;
  if (is_gecko) menuItem = howDoesGeckoHandleEvents;
  menuItem.className = "menuItemHighlight";
}

function unhighlight (howDoesGeckoHandleEvents) {
  if (is_ie4up) menuItem = window.event.srcElement;
  if (is_gecko) menuItem = howDoesGeckoHandleEvents;
  menuItem.className= "menuItem";
}

function explain (e) {
  if (is_ie4up) icon = window.event.srcElement;
  if (is_gecko) icon = e.target;
  icon = document.getElementById(menuItem.id.substring(0,menuItem.id.length-4));
  top.location = icon.iconLink;
}
function createMenu () {
  name = this.name;
  menuItem = this.menuItem;
  menuLink = this.menuLink;
  iconLink = this.iconLink;
  iconName = this.iconName;
  positionYIcon = this.positionYIcon;
  positionYMenu = this.positionYMenu;
  
  menuName[menuName.length] = name;
  
  // Create the icon
  icon = document.createElement("img");
  icon.src            = "../" + name + "_off.gif";
  icon.id             = name;
  icon.className      = "menuIcon";
  icon.style.top      = positionYIcon + "px";
  icon.iconLink       = iconLink;
  if (is_ie4up) icon.setAttribute ("onclick", explain, false);
  if (is_gecko) icon.addEventListener ("click", explain, false);
  
  if (is_ie4up) icon.setAttribute ("onmouseover", show, false);
  if (is_ie4up) icon.setAttribute ("onmouseout", hide, false);
  if (is_gecko) icon.addEventListener ("mouseover", show, false);
  if (is_gecko) icon.addEventListener ("mouseout", hide, false);
  document.body.appendChild (icon);
  
  // Create the menu
  items = document.createElement("div");
  if (is_ie4up) items.setAttribute ("onmouseover", holdItem, false);
  if (is_ie4up) items.setAttribute ("onmouseout", releaseItem, false);
  if (is_gecko) items.addEventListener ("mouseover", holdItem, false);
  if (is_gecko) items.addEventListener ("mouseout", releaseItem, false);

  html = "";
  html += "<div class='menuHeading'>" + iconName + "</div><div style='padding:2px;'></div>";
  for (var i=0; i<menuItem.length; i++) {
    html += "  <div "
    html += "  onmouseover='highlight(this);'  "
    html += "  onmouseout='unhighlight(this);'  "
    html += "  onclick='top.location=\"" + menuLink[i] + "\"'  ";
    html += "  id='" + name + i + "'";
    html += "  class='menuItem'";
    html += "  >  ";
    html += menuItem[i];
    html += "</div>";
// Next line lists all links in document, for site map creation
// document.write("<P><a href='" + menuLink[i] + "'>" + menuItem[i] + "</a></P>"); 
  }
  items.innerHTML        = html;
  items.id               = name + "Item";
  items.style.visibility = "hidden";
  items.style.top        = positionYMenu + "px";
  items.className        = "menuBox";
  document.body.appendChild (items);
}

// Check Browser
if (!(is_nav6up || is_gecko || is_ie5up)) {
  document.write("<center><a href='../sitemap.html'>Sitemap</a></center>");
  }
  else {
  // Actual Menu Items and Labels

  document.write('<div id="leftBar" class="bar" style="left:0px; border-right-style:solid;">&nbsp;</div>');

  var aboutMe = new Menu("aboutMe", "About Me!", "../aboutMe/intro.html", 20, 20);
  aboutMe.addMenuItem("Contact Me", "../aboutMe/contact.html");
  aboutMe.addMenuItem("Achievements", "../aboutMe/achievements.html");
  aboutMe.addMenuItem("FAQs about me", "../aboutMe/faq.htm");
  aboutMe.addMenuItem("Whats with Anvilsoup", "../aboutMe/anvilsoup.html");
  aboutMe.createMenu();
 
  var primary = new Menu("primary", "Primary School", "../aboutMe/intro.html", 80, 80);
  primary.addMenuItem("UFO Story", "../primary/ufo_story.html");
  primary.addMenuItem("Space", "../primary/space.html");
  primary.addMenuItem("Ancient Civilisations", "../primary/ancient_civilisations.html");
  primary.addMenuItem("Counting On Einstein", "../primary/counting_on_einstein.html");
  primary.addMenuItem("Escape from a Neutron Star", "../primary/escape_from_a_neutron_star.html");
  primary.addMenuItem("Living Things", "../primary/living_things.html");
  primary.addMenuItem("Caving Out", "../primary/caving_out.html");
  primary.addMenuItem("Aboriginal Story", "../primary/sky_weight.html");
  primary.createMenu();
  
  var trivia = new Menu("trivia", "Serious Trivia", "../aboutMe/intro.html", 140, 140);
  trivia.addMenuItem("Piano Tuning / Mathematics", "../trivia/piano.htm");
  trivia.addMenuItem("Exegetical Fallacies", "../trivia/exegesis.htm");
  trivia.addMenuItem("Computer Ports", "../trivia/ports_originality.html");
  trivia.addMenuItem("Prose and Rhetoric", "../trivia/rhetoric.html");
  trivia.addMenuItem("HTML documentation", "../trivia/html.html");
  trivia.addMenuItem("Space", "../trivia/space.html");
  trivia.addMenuItem("Highly Effective People", "../trivia/7habits.html");
  trivia.addMenuItem("Stem Cells", "../trivia/stem_cells.html");
  trivia.addMenuItem("Ten Commandments", "../trivia/five_little_fingers.html");
  trivia.addMenuItem("Freeware", "../trivia/freeware.html");
  trivia.createMenu();
 
  var art = new Menu("art", "Artistic Stuff", "../aboutMe/intro.html", 200, 200);
  art.addMenuItem("Computer Art", "../art/gallery.html");
  art.addMenuItem("Noises in the Night", "../art/noises.htm");
  art.addMenuItem("Gerard Manley Hopkins", "../art/hopkins.html");
  art.createMenu();
  
  var stories = new Menu("stories", "Short Stories", "../aboutMe/intro.html", 260, 260);
  stories.addMenuItem("Gothic Short Story", "../stories/gothic.htm");
  stories.addMenuItem("An Introduction", "../stories/introduction.html");
  stories.addMenuItem("Reboot (PR#6)", "../stories/reboot.html");
  stories.addMenuItem("Resolution", "../stories/resolution.html");
  stories.addMenuItem("The Rich Young Ruler", "../stories/rich_young_ruler.html");
  stories.addMenuItem("If trees could walk", "../stories/trees.html"); 
  stories.createMenu();
  
  var jokes = new Menu("jokes", "Funnies", "../aboutMe/intro.html", 320, 280);
  jokes.addMenuItem("Light Bulb Jokes", "../jokes/lights.html");
  jokes.addMenuItem("Why I never wash", "../jokes/never_wash.html");
  jokes.addMenuItem("For Profit", "../jokes/for_profit.html");
  jokes.addMenuItem("Wild Australia", "../jokes/australia.html");
  jokes.addMenuItem("Get Rich Quick!", "../jokes/get_rich_quick.html");
  jokes.createMenu();

  var interact = new Menu("interact", "Interact", "../aboutMe/intro.html", 380, 340);
  interact.addMenuItem("View Guestbook", "http://htmlgear.lycos.com/guest/control.guest?u=anvilsoup&i=1&a=view");
  interact.addMenuItem("Sign Guestbook", "http://htmlgear.lycos.com/guest/control.guest?u=anvilsoup&i=1&a=sign");
  interact.addMenuItem("Links", "../interact/links.html");
  interact.addMenuItem("Search Site", "../interact/search.html");
  interact.createMenu();

    // Preload "on" icon
    on1 = new Image(109,109);
    on1.src = "../building_on.gif";
    on2 = new Image(109,109);
    on2.src = "../people_on.gif";
    on3 = new Image(109,109);
    on3.src = "../reaching_on.gif";
    on4 = new Image(109,109);
    on4.src = "../world_on.gif";

  /**********************************************
   * Generate next-back links
   */

  var s = document.location.href.split("/");
  var icon = "aboutMe";
  var iconNumber = -1;
  var menuLink = new Array();
  var menuItem = new Array();
  var currentItem = -1;
  var nextItem = "";
  var nextLink = "";
  var prevItem = "";
  var prevLink = "";

  /**
   * Find out which icon we are in
   */
  for (var i=0; i<s.length; i++) {
    for (var j=0; j<menuName.length; j++) {
      if (menuName[j] == s[i]) {
        icon = s[i];
        iconNumber = j;
      }
    }
  }
  menuLink = eval(icon).menuLink;
  menuItem = eval(icon).menuItem;

  /**
   * Find out the current item
   */
  for (var i=0; i<menuLink.length; i++) {
    if (menuLink[i].indexOf(s[s.length-1]) != -1) { // Find out which menuLink
      currentItem = i;
    }
  }

  /**
   * Get Next Item
   */
  if (currentItem < menuLink.length-1) { // Not the last link in the icon set
    nextLink = menuLink[currentItem+1];
    nextItem = menuItem[currentItem+1];
    } else { // Next Icon
    if (iconNumber < menuName.length-1) { // Not the last icon set
      nextLink = eval(menuName[iconNumber+1]).menuLink[0];
      nextItem = eval(menuName[iconNumber+1]).menuItem[0];
    }
  }

  /**
   * Get Previous Item
   */
  if (currentItem > 0) { // Not the first link in the icon set
    prevLink = menuLink[currentItem-1];
    prevItem = menuItem[currentItem-1];
    } else { // Previous Icon
    if (iconNumber > 0) { // Not the first icon set
      icon = eval(menuName[iconNumber-1]);
      prevLink = icon.menuLink[icon.menuLink.length-1];
      prevItem = icon.menuItem[icon.menuItem.length-1];
    }
  }

  if (currentItem==-1 && s[s.length-1]!="index.html") {
    prevItem = "";
    nextItem = "";
  }

  /**
   * Write the links
   */
  document.write("<P class='nav' style='text-align:center'>");
  if (prevItem != "") document.writeln("<a href='" +prevLink+ "'>&lt; " +prevItem+ "</a>");
  if (prevItem != "" && nextItem != "") document.write("| ");
  if (nextItem != "") document.writeln("<a href='" +nextLink+ "'>" +nextItem+ " &gt;</a>");
  document.write("</p>");

  /*************************************
   * Resize the bars
   */

  function resizeHeight() {
    var height=0;
    if (is_ie4up) {
      if (height<document.body.scrollHeight) height=document.body.scrollHeight;
      if (height<screen.availHeight) height=screen.availHeight;
    }
    if (is_gecko) {
      if (height<document.height) height=document.height;
      if (height<screen.availHeight) height=screen.availHeight;
    }
    height=height+30;
      document.getElementById("leftBar").style.height=height + "px";
  }

  if (is_ie4up) document.body.setAttribute ("onload", resizeHeight, false);
  if (is_gecko) window.onload=resizeHeight;
}