//
// this file contains code used by the menu bar
//

var imgRootDepth = 0;

// imgRootDepth is used to determine the path to the images and must be
// configured differently depending upon how far the image directory
// is from the root of the website.
//
// examples
//  path to image dir             imgRootDepth
//  ------------------------------------------
//  www.javaranch.com/images          0
//  www.javaranch.com/dgr/jr/images   2
//  127.0.0.1/javaranch/images        1

var maxmenu = 10;

var imgOn = new Array(maxmenu);
var imgOff = new Array(maxmenu);
var imgHelp = new Array(maxmenu+1); // extra space for the blank help
var imgRoot = '/images/';
var imgStat = 0;

function loadimages(imgroot) {
// dummy - left in to avoid changing body tags
}

// set the menu image to the "on" (on mouseover)
function setImageOn(imgNum) {
	if ( document.images ) {
	 // if the user is running javascript, we can eliminate the alt tags
	 // since the help is presented via this routine
   document['m'+ imgNum].alt = '';
   document['m'+ imgNum].src = imgOn[imgNum-1].src;
   document.imghelp.src = imgHelp[imgNum-1].src;
  }
}

// set the menu image to the "off" (on mouseout)
function setImageOff(imgNum) {
	if ( document.images ) {
   document['m'+ imgNum].src = imgOff[imgNum-1].src;
   document.imghelp.src = imgHelp[maxmenu].src;
  }
}

// main routine start here
if ( document.images ) {

  // determine the image root
  var pattern = /(\w+):\/\/([\w.]+)\/(\S*)/;
  var result = document.URL.match(pattern);
  var path = result[3];

  var p = 0;
  var sl = 0;

  // count number of slashes in path
  while (( p=path.search(/\//) ) >=0 ) {
   sl++;
   path = path.slice(p+1);
  }

  // check number of slashes against imgRootDepth
  // adding '../' if neccessary
  for (var i=imgRootDepth; i < sl; i++) {
    imgRoot = '../' + imgRoot;
  }

  // load the images
  for (var i=0; i < maxmenu; i++) {
    imgOff[i] = new Image();
    imgOn[i] = new Image();
    imgHelp[i] = new Image();
    imgOff[i].src = imgRoot + 'm' + eval(i+1) + 'off.gif'
    imgOn[i].src = imgRoot + 'm' + eval(i+1) + 'on.gif'
    imgHelp[i].src = imgRoot + 'm' + eval(i+1) + 'help.gif'
  }
  imgHelp[maxmenu] = new Image();
  imgHelp[maxmenu].src = imgRoot + 'm0help.gif';

}


