/************************************************************
* I had some trouble with the 'eval' function used below in *
* several places: NN4x apparently interprets it differently *
* from NN3x, so for now I've split up the functions using   *
* 'eval' in two parts: one for NN3, one for NN4; I'll look  *
* into it later when I have more time and when I _really_   *
* understand what I'm doing... >:|                          *
* At least it WORKS in both versions now.                   *
************************************************************/

function init() {
   // populate lynx array
   initArray();

   // track the content of the 'main' frame
   top.checkFile     = loadedFile();

   // set the HEADER's sub title
   top.byline        = 'art made Manifest';

   // track which linkfile has focus
   top.currentFocus  = 'lynx2';
   top.previousFocus = 'lynx2';

   // if we're not running
   top.timerRunning  = false;
   // there's nuthin' to clearTimeout
   top.checkLynx     = null;

   // define mask boundaries to fill PIX_NDX.HTML with images
   top.start = 0;
   top.end   = top.start + top.mask - 1;
}

function initArray() {
   top.memArray    = new Array();
   top.memArrayIDX = 0;
   // check every frame for hyperlinks
   for (var x = 0; x < top.frames.length; x++) {
      // the checked frame has 1 or more hyperlinks
      if (top.frames[x].document.links.length > 0) {
         // add its name to the array
         top.memArray[top.memArrayIDX] = top.frames[x].name;
         // increment the array index
         top.memArrayIDX++;
      }
   }
}

   // get the name of the file loaded in the 'main' frame
function loadedFile() {
   var tname      = top.main.location.pathname;
   var loadedFile = tname.substring(tname.lastIndexOf('/') + 1);
   return(loadedFile);
}

   // get the name of the file pointing to 'main'
function memFile(x, y) {
   if (navigator.appVersion.charAt(0) == 3) {
      var tname   = top.eval(top.memArray[x]).document.links[y].pathname;
      var memFile = tname.substring(tname.lastIndexOf('/') + 1);
   }

   if (navigator.appVersion.charAt(0) == 4) {
      var tname1  = 'top.' + top.memArray[x] + '.document.links[y].pathname';
      var tname2  = eval(tname1);
      var memFile = tname2.substring(tname2.lastIndexOf('/') + 1);
   }

   return(memFile);
}

function runTimer() {
   if (top.timerRunning)
      top.timerRunning = false;
   clearTimeout(top.checkLynx);

   // the file loaded in the 'main' frame has changed
   if (top.checkFile != loadedFile()) {
      top.checkFile = loadedFile();
      refresh();
   }

   top.checkLynx    = setTimeout('runTimer()', 100);
   top.timerRunning = true;
}

function refresh() {
   setFocus();

   // we clicked in the same frame
   if (top.currentFocus == top.previousFocus) {
      if (navigator.appVersion.charAt(0) == 3)
         top.eval(top.currentFocus).location.reload();
      if (navigator.appVersion.charAt(0) == 4) {
         var current = 'top.' + top.currentFocus;
         eval(current).location.reload();
      }
   } else {
      if (navigator.appVersion.charAt(0) == 3) {
         top.eval(top.currentFocus).location.reload();
         top.eval(top.previousFocus).location.reload();
      }
      if (navigator.appVersion.charAt(0) == 4) {
         var current = 'top.' + top.currentFocus;
         eval(current).location.reload();
         var previous = 'top.' + top.previousFocus;
         eval(previous).location.reload();
      }
   }

   // reload header to reflect 'main' file's TITLE
   top.header.location.reload();
}

function setFocus() {
   var memFound = false;
   // check every 'memorized' file (x) that has hyperlinks
   for (var x = 0; x < top.memArray.length; x++) {
      // check every link (y) in that file for its A href value
      if (navigator.appVersion.charAt(0) == 3) {
         for (var y = 0; y < top.eval(top.memArray[x]).document.links.length; y++) {
            // file's A href corresponds w/ 'main' fileName
            if (memFile(x, y) == loadedFile()) {
               // keep track of history
               top.previousFocus = top.currentFocus;
               // set focus to file that points to 'main' fileName
               top.currentFocus = top.memArray[x];
               // go reload affected frames
               memFound = true;
               break;
            }
         }
      }
      if (navigator.appVersion.charAt(0) == 4) {
         var len1 = 'top.' + top.memArray[x] + '.document.links.length';
         var len2 = eval(len1);
         for (var y = 0; y < len2; y++) {
            // file's A href corresponds w/ 'main' fileName
            if (memFile(x, y) == loadedFile()) {
               // keep track of history
               top.previousFocus = top.currentFocus;
               // set focus to file that points to 'main' fileName
               top.currentFocus = top.memArray[x];
               // go reload affected frames
               memFound = true;
               break;
            }
         }
      }
      if (memFound)
         break;
   }
}

function setLink(fileName, linkTxt, mouseOver) {
   if (fileName == loadedFile()) {
      // use the mouseover text as the 'main' file's TITLE
      top.byline = mouseOver;
      // write the link as plain text to reflect where we are
      document.write(linkTxt);
   } else {
      document.write(
         '&nbsp;&nbsp;&nbsp;'
       + '&nbsp;&nbsp;&nbsp;'
       + '<A href="' + fileName + '"'
       + '   target="main"'
       + '   onMouseOver="self.status = \'' + mouseOver + '\'; return true"'
       + '   onMouseOut="self.status = \'Document: Done\'; return true">'
       + linkTxt + '</A>'
      );
   }

   document.write('<BR>');
}

