// rollover functions
// asw  2001

function showElements() {
      var tag_names = "";
      for (i=0; i<document.all.length; i++)
          tag_names = tag_names + document.all(i).tagName + " ";
      alert("This document contains: " + tag_names);
  }

function changeImg(name, image) {
  var thisImg;
  thisImg = eval("document." + name);
  thisImg.src = image;
}

// menuAxn called when mouse rolls over or off an anchor link
// ancha = <A href anchor object
// action = 'out' or 'over'
// image = name of pointer image to change, if any
//   if image is specified, the following two images are interchanged:
//   pointer_blank.gif and pointer.gif, with pointer.gif displayed when
//   the mouse is over the link.

var imgdir = "global/images/";
var arrow_blank = imgdir + "arrow_blank.gif";
var arrow_sect = imgdir + "arrow.gif";
var arrow_page = imgdir + "arrow_blue.gif";

function menuOver(name) {
    return menuAxn(null, 'over', name);
}
function menuOut(name) {
    return menuAxn(null, 'out', name);
}

function menuAxn(doc, action, image) {
    var thisImg = eval("document." + image);

    if(thisImg == null) return;

    // navigator 3?  abort, abort
    if(navigator.userAgent.indexOf("Mozilla/3") == 0) return;

    if(action == "over") {
        thisImg.prevsrc = thisImg.src;
        thisImg.src = arrow_sect;
    }
    else if(action == "out") {
        thisImg.src = (thisImg.prevsrc != null) ?
        	thisImg.prevsrc : arrow_blank;
    }
    else {
        // whine
        alert("menuAxn: neither over nor out");
    }
}

// finds index of needle in haystack
// searching backwards from end of haystack
function lastIndexOf(needle, haystack) {
    //alert("needle:" + needle + ", haystack:" + haystack);

    if(needle == null || haystack == null) return -1;

    var len = needle.length;
    var i = haystack.length - len;

    for(; i >= 0; i--) {
        if(haystack.substring(i, i + len) == needle)
            return i;
    }
    return -1;
}

// display page arrow next to current page in secondary nav
function show_curnav_notworkingwhy(prefix, linkmap) {
    var i, j;
    var file = document.location + "";  // cast to string

    // strip path from document name
    // if path ends in "/", get directory name
//    if(file.substring(file.length, file.length) == "/")
//        file = file.substring(0, file.length - 1);
    file = ((j = lastIndexOf("/", file)) >= 0) ?
        file.substring(j + 1, file.length) : file;

    if(file.length == 0) return;
    var links = document.links;

    // search for link matching current document
    for(i = 1; i <= linkmap.length; i++) {
        var funkA = linkmap[i];
        if(funkA == null) continue;

        //alert("checking " + file + " against " + funkA);
        if(funkA.indexOf(file) >= 0) {
	  alert("found matching anchor: " + funkA);
	  var funkImg = eval("document." + prefix + i + "p");
	  funkImg.src = arrow_page;
	  break;
        }
    }
}

// display page arrow next to current page in secondary nav
// (doesn't work in N4, sigh)
function show_curnav(prefix, max) {

    var i, j;
    var file = document.location + "";  // cast to string

    // navigator 3?  abort, abort
    if(navigator.userAgent.indexOf("Mozilla/3") == 0) return;

    // strip path from document name
    file = ((j = lastIndexOf("/", file)) >= 0) ?
        file.substring(j + 1, file.length) : file;

    if(file.length == 0) return;
    var links = document.links;

    // search for link matching current document
    for(i = 0; i <= max; i++) {
        var aname = "a_" + prefix + i + "p";
        var funkImg = eval("document." + prefix + i + "p");
        var funkA = null;

        // find anchor (link) in doc corresonding to this aname
        for(j = 0; j < links.length; j++) {
	  if(links[j].name == aname) {
	      funkA = links[j].href + "";
	      break;
	  }
        }
        if(funkA == null) continue;

        //alert("checking " + file + " against " + funkA);
        if(funkA.indexOf(file) >= 0) {
	  //alert("found matching anchor: " + funkA);
	  funkImg.src = arrow_page;
	  break;
        }
    }
}

