// Relevant bits snipped from the HTML:
// #mMenu starting style:
//        position: absolute;
//        top: 1px;
//        left:  1px;
//        visibility: hidden;
//        z-index: 300;
//        width: 130px; 
//        line-height: 0;
// body onload="initMenu()"
// div id="mMenu"


// Some Global Variables:
var menuFiles = new Array();
var menuPlace = new Array();
var menuAltex = new Array();
var titleIm1, titleIm2;
var preOff = new Array();
var preOn = new Array();
var theTarg = "_self";
var aPointer; // The activation button
var mPointer; // The Menu itself
var closeInterval; // Menu Closing flag
var clockPointer; // The demonstration "Clock" example
var blearg = getCookie("setup");
if (document.layers) { blearg = "default" };

// =====================================================================
// a few flags for things that are sometimes turned on, but usually not.
// To activate one of these, add a <script> tag in the head that sets
// the value for each one you need to true.
var setCheckPulse = false; // The pulsing filter from the top of tut-10
                           // requires that you also include filters.js
var setClockTimer = false; // The javascript clock example from tut-DHTML-clock
// =====================================================================



function initMenuGuts() {
  // Later, we'll decide which of these to use based on a cookie setting.
  // For the moment, there shall be only one.
  switch (blearg) {
    case "blue":
      menuFiles[0] = "b0";	menuPlace[0] = "#";		menuAltex[0] = "Menu Open";
      menuFiles[1] = "b1";	menuPlace[1] = "/60-270/index.php";	menuAltex[1] = "News";
      menuFiles[2] = "b2";	menuPlace[2] = "/60-270/schedule.php";	menuAltex[2] = "Schedule";
      menuFiles[3] = "b3";	menuPlace[3] = "/60-270/outline.php";	menuAltex[3] = "Outline";
      menuFiles[4] = "b4";	menuPlace[4] = "/60-270/tutorials.php";menuAltex[4] = "Tutorials";
      menuFiles[5] = "b5";	menuPlace[5] = "/60-270/classlist.php";menuAltex[5] = "Class List";
      menuFiles[6] = "b6";	menuPlace[6] = "/60-270/project.php";	menuAltex[6] = "Project";
      menuFiles[7] = "b7";	menuPlace[7] = "/60-270/tools.php";	menuAltex[7] = "Tools";
      menuFiles[8] = "b8";	menuPlace[8] = "/60-270/settings.php";	menuAltex[8] = "Settings";
      menuFiles[9] = "b9";	menuPlace[9] = "/60-270/links.php";	menuAltex[9] = "Links";
      titleIm1 = "/60-270/images/b60-270.gif";	titleIm2 = "/60-270/images/bAdvWebDes.gif";
      break;
    case "pain":
      menuFiles[0] = "p0";	menuPlace[0] = "#";		menuAltex[0] = "Menu Open";
      menuFiles[1] = "p1";	menuPlace[1] = "/60-270/index.php";	menuAltex[1] = "News";
      menuFiles[2] = "p2";	menuPlace[2] = "/60-270/outline.php";	menuAltex[2] = "Outline";
      menuFiles[9] = "p3";	menuPlace[9] = "/60-270/schedule.php";	menuAltex[9] = "Schedule";
      menuFiles[4] = "p4";	menuPlace[4] = "/60-270/tutorials.php";menuAltex[4] = "Tutorials";
      menuFiles[5] = "p5";	menuPlace[5] = "/60-270/classlist.php";menuAltex[5] = "Class List";
      menuFiles[6] = "p6";	menuPlace[6] = "/60-270/project.php";	menuAltex[6] = "Project";
      menuFiles[7] = "p7";	menuPlace[7] = "/60-270/tools.php";	menuAltex[7] = "Tools";
      menuFiles[8] = "p8";	menuPlace[8] = "/60-270/links.php";	menuAltex[8] = "Links";
      menuFiles[3] = "p9";	menuPlace[3] = "/60-270/settings.php";	menuAltex[3] = "Settings";
      titleIm1 = "/60-270/images/p60-270.png";	titleIm2 = "/60-270/images/pAdvWebDes.png";
      break;
    case "yellow": // Uses the same images as the "original" version.
    case "main":
      menuFiles[0] = "d0";	menuPlace[0] = "#";		menuAltex[0] = "Menu Open";
      menuFiles[1] = "d1";	menuPlace[1] = "/60-270/index.php";	menuAltex[1] = "News";
      menuFiles[2] = "d2";	menuPlace[2] = "/60-270/schedule.php";	menuAltex[2] = "Schedule";
      menuFiles[3] = "d3";	menuPlace[3] = "/60-270/outline.php";	menuAltex[3] = "Outline";
      menuFiles[4] = "d4";	menuPlace[4] = "/60-270/tutorials.php";menuAltex[4] = "Tutorials";
      menuFiles[5] = "d5";	menuPlace[5] = "/60-270/classlist.php";menuAltex[5] = "Class List";
      menuFiles[6] = "d6";	menuPlace[6] = "/60-270/project.php";	menuAltex[6] = "Project";
      menuFiles[7] = "d7";	menuPlace[7] = "/60-270/tools.php";	menuAltex[7] = "Tools";
      menuFiles[8] = "d8";	menuPlace[8] = "/60-270/settings.php";	menuAltex[8] = "Settings";
      menuFiles[9] = "d9";	menuPlace[9] = "/60-270/links.php";	menuAltex[9] = "Links";
      titleIm1 = "/60-270/images/d60-270.gif";	titleIm2 = "/60-270/images/dAdvWebDes.gif";
      break;
    case "black":
    default:
      menuFiles[0] = "m0";	menuPlace[0] = "#";		menuAltex[0] = "Menu Open";
      menuFiles[1] = "m1";	menuPlace[1] = "/60-270/index.php";	menuAltex[1] = "News";
      menuFiles[2] = "m2";	menuPlace[2] = "/60-270/outline.php";	menuAltex[2] = "Outline";
      menuFiles[3] = "m3";	menuPlace[3] = "/60-270/schedule.php";	menuAltex[3] = "Schedule";
      menuFiles[4] = "m4";	menuPlace[4] = "/60-270/tutorials.php";menuAltex[4] = "Tutorials";
      menuFiles[5] = "m5";	menuPlace[5] = "/60-270/classlist.php";menuAltex[5] = "Class List";
      menuFiles[6] = "m6";	menuPlace[6] = "/60-270/project.php";	menuAltex[6] = "Project";
      menuFiles[7] = "m7";	menuPlace[7] = "/60-270/tools.php";	menuAltex[7] = "Tools";
      menuFiles[8] = "m8";	menuPlace[8] = "/60-270/links.php";	menuAltex[8] = "Links";
      menuFiles[9] = "m9";	menuPlace[9] = "/60-270/settings.php";	menuAltex[9] = "Settings";
      titleIm1 = "/60-270/images/m60-270.gif";	titleIm2 = "/60-270/images/mAdvWebDes.gif";
    };
  };

function initMenu() {
  if (document.layers) { // what the heck are you using that for?
    mPointer = window.document.mMenu;
    aPointer = window.document.aMenu;
    aPointer.x = window.innerWidth - 131;
    mPointer.x = window.innerWidth - 131;
    aPointer.visibility = "visible";
    } else if (document.all) { // IE method:
    mPointer = document.all.mMenu;
    aPointer = document.all.aMenu;
    aPointer.style.visibility = "visible";
    } else { // NS 5+ method:
    mPointer = document.getElementById("mMenu");
    aPointer = document.getElementById("aMenu");
    aPointer.style.visibility = "visible";
    };

  initMenuGuts();

  var menuGuts = "";
  var painX = 0;
  var painY = 0;
  var painZ = 0;

// build the contents for the new menu (changes based on cookie content)

  for (var i=1;i<menuFiles.length;i++) {
    preOff[i] = new Image();
    preOff[i].src = "/60-270/images/"+ menuFiles[i]+"-0.png";
    preOn[i] = new Image();
    preOn[i].src = "/60-270/images/"+ menuFiles[i]+"-1.png";

    if (blearg == "pain") {
      painX = Math.round(Math.random() * 800);
      painY = Math.round(Math.random() * 600);
      painZ = Math.round(Math.random() * 200) + 100;
      menuGuts += "<div style=\"position:absolute;top:"+painY+"px;right:"+painX+"px;z-index:"+painZ+"\">";
      menuGuts += "<a target=\"" + theTarg + "\" href=\"" + menuPlace[i] + "\"";
      menuGuts += " onmouseover=\"menuItemEnter(menuImg"+i+","+i+")\"";
      menuGuts += " onmouseout=\"menuItemExit(menuImg"+i+","+i+")\"";
      menuGuts += " ><img src=\"/60-270/images/" + menuFiles[i] + "-0.png\" border=\"0\" name=\"menuImg"+i+"\" alt=\"" + menuAltex[i] + "\" /></a></div>";
      } else {
      menuGuts += "<a target=\"" + theTarg + "\" href=\"" + menuPlace[i] + "\"";
      menuGuts += " onmouseover=\"menuItemEnter(menuImg"+i+","+i+")\"";
      menuGuts += " onmouseout=\"menuItemExit(menuImg"+i+","+i+")\"";
      menuGuts += " ><img src=\"/60-270/images/" + menuFiles[i] + "-0.png\" border=\"0\" name=\"menuImg"+i+"\" alt=\"" + menuAltex[i] + "\" /></a>";
      if (i < (menuFiles.length-1)) {menuGuts += "<br />";};
      };
    };
  if (document.layers) { // more ns4 specific stuff
    document.images.head60270.src = titleIm1;
    document.images.headadvwebdes.src = titleIm2;
    preOff[0] = new Image();
    preOff[0].src = "/60-270/images/d0-0.png";
    preOn[0] = new Image();
    preOn[0].src = "/60-270/images/d0-1.png";
    preOff[9] = new Image();
    preOff[9].src = "/60-270/images/d9-0.png";
    preOn[9] = new Image();
    preOn[9].src = "/60-270/images/d9-1.png";
    } else { // don't do this in NS4:
    document.getElementById("head60270").src = titleIm1;
    document.getElementById("headadvwebdes").src = titleIm2;
    // Change the 'menu' button to the right one,
    // and the menu open function to onmouseover instead of onclick
    aPointer.innerHTML = "<a href=\"" + menuPlace[0]+ "\" onmouseover=\"activateMenu()\"><img src=\"/60-270/images/"+menuFiles[0]+"-0.png\" alt=\""+menuAltex+"\" border=\"0\" /></a>";
    // overwrite the old menu with the new one
    mPointer.innerHTML = menuGuts;
    };

  if (setCheckPulse) {
    // This means to start up the pulsing glow filter example from tut-10
    // requires filters.js
    checkPulse();
    };
  if (setClockTimer) {
    // Start up the clock timer from tut-DHTML-clock
    activateClock();
    };
  }; // End of initMenu();

// These functions open/close the menu, and highlight images in NS5+ and IE5+
function activateMenu() {
  mPointer.style.visibility = "visible";
  };
function closeMenu() {
  mPointer.style.visibility = "hidden";
  };
function menuItemEnter(theImg,place) {
  theImg.src = preOn[place].src;
  clearInterval(closeInterval);
  };
function menuItemExit(theImg,place) {
  theImg.src = preOff[place].src;
  closeInterval = setInterval("closeMenu()",800);
  };

// These functions open/close the menu, and highlight images in NS4 - reduced functionality
function n4menuClose() {
  mPointer.visibility = 'hidden';
  };
function n4menuOpen() {
  mPointer.visibility = 'visible';
  };
function n4menuItemExit(theImg,place) {
  theImg.src = preOff[place].src;
  };
function n4menuItemEnter(theImg,place) {
  theImg.src = preOn[place].src;
  };

function activateClock() {
  // Note: this will only work in browser versions of
  // 5 and above (for any browser)
  if (document.layers) {
    return false; // prevents from running in NS4
    };

  // Get the pointer to the cell the clock will be in:
  clockPointer = document.getElementById("theClock"); 
  // We don't care about keeping the flag for this interval, so it's not saved
  setInterval("runClock()",1000); // update the clock once a second.
  };

function runClock() {
  // Currently, this clock does AM/PM time
  var timeNow = new Date(); // get the current time
  var outPut = ""; // the time string to print - start blank
  var ending = "AM"; // is it AM or PM?  Default AM
  if (timeNow.getHours() > 12) {
    ending = "PM";
    outPut += (timeNow.getHours() - 12) + ":";
    } else {
    outPut += timeNow.getHours() + ":";
    };

  if (timeNow.getMinutes() < 10) {
    outPut += "0";
    };
  outPut += timeNow.getMinutes() + ":";

  if (timeNow.getSeconds() < 10) {
    outPut += "0";
    };
  outPut += timeNow.getSeconds() + " " + ending;
  clockPointer.innerHTML = outPut;
  };

