/*
Script for Navigation Bar.  Intended to be embedded in the head of a frame that is to manage a parent's "display frame".  Links in "A" statements of the class "linker" in the Navigatin Bar's frame are managed by this script and coordinated with the document loading of the display-frame.

There must be in the header a set of javascript statements that set the "baseColor", "overColor", and "selectColor" of the linking text and identify the parent frame's display frame (e.g. "var targetFrame = parent.MainFrame;". In addition, linked pages must have an onLoad statement that contains "if (parent.arrived) parent.arrived(document.location);".
*/

var actionLinks = new Array();
var curIndex = -1;
var hasStyles = false;

/*
the variable, hasStyles, is set in initNav() and is intended to detect browers that support the "style" property of HTML elements  - which is all but the versions of NN prior to 6.  If hasStyles is false, all changes to the color of the links are skipped, as is the response to the loading of a target page.
*/

function locfileName(xlocpath)
{
  dc = xlocpath.lastIndexOf('/');
  if (dc > 0)
  { frags = xlocpath.split('/'); }
  else
  { frags = xlocpath.split('\\'); }
  k = frags.length;
  return frags[k - 1];
}

function matchLink(xlocpath)
{
  thisFileName = locfileName(xlocpath);
  thisLinkIndex = -1;
  for (var i = 0; i < actionLinks.length; i++)
  {
    thatFileName = locfileName(actionLinks[i].basePath);
    if (thisFileName == thatFileName)
    {
       thisLinkIndex = i;
       break;
    }
  }
  return thisLinkIndex;
}


function resetLinksToIndex(j)
{
  curIndex = j;
  for (var i = 0; i < actionLinks.length; i++)
  {
    actionLinks[i].style.color = baseColor;
  }
  if (j >= 0)
  { actionLinks[j].style.color = selectColor;
  }
}

function locChange(xloc)
{
  resetLinksToIndex(matchLink(xloc.pathname));
}


function initNav()
{
  bwr = navigator.appName;
  ver = parseInt(navigator.appVersion, 10);
  if ((bwr != "Netscape") || (ver > 4))
  {
    hasStyles = true;
    parent.arrived = locChange;
  }
  for (var i = 0; i < document.links.length; i++)
  {  
    thisLink = document.links[i];
    if (!hasStyles || thisLink.className == "linker")
    {  
       nextJ = actionLinks.length;
       actionLinks[nextJ] = thisLink;
       thisLink.myIndex = nextJ;
       thisLink.baseHref = thisLink.href;
       thisLink.basePath = thisLink.pathname;
       thisLink.href = "#";
       thisLink.onclick = clickMouse;
       if (hasStyles)
       {
         thisLink.style.color = baseColor;
         thisLink.onmouseover = overMouse;
         thisLink.onmouseout = outMouse;
       }
    }
  }
}      

function overMouse()
{
  if (this.myIndex != curIndex)
  {
    this.style.color = overColor;
  }
}

function outMouse()
{
  if (this.myIndex == curIndex)
  {
    this.style.color = selectColor;
  }
  else
  {
    this.style.color = baseColor;
  }
}

function clickMouse()
{
  targetFrame.location = this.baseHref;
  if (hasStyles)
  {
    resetLinksToIndex(-1);
  }
}

