// Copyright 2002 Marlin Ouverson. (marlin@neverslow.com)
// Used by AusAm Biotechnologies, Inc. with permission.

// Code forks support IE, NN6 (and NN4.x without the effect)
// Initial assignments for visible text and highighted name.
// Can set to "introduction" and "" to have other introductory text.

// Global initialization of textReveal variables; initialize locally in files where used.
var currLink  = "";       // Highlighted menu item, if any.
var currSubLink  = "";    // Highlighted menu item, if any.
var currSubMenu= "";      // Expanded sub-menu, if any.
var currSubSubMenu = "";  // Expanded sub-sub-menu, if any.
var currOpenedArrow = ""; // Expanded sub-sub-menu's indicator arrow's name, if any.

function closeTheArrow() { // Unconditionally 'close' the current arrow indicator.
  if (is_nav4) { return; } // No-op for NN4.

  if (is_ie4up) {
//      document.all(currOpenedArrow).src = menuArrows[0].src;
  }

  if ((!is_ie) && (document.getElementById && document.body.style)) { // Non-sniffer test for NN6/'standards-compliant' browsers.
//       document.getElementById(currOpenedArrow).src = menuArrows[0].src;
  }
}

// Highlight current link, de-highlight others. (Color of any text is determined by stylesheets et al.)
function highlight(id) { // Takes the ID of any valid block (an href link, for example, to constrain width of the highlight effect)
  if (is_nav4) { return; // No-op for NN4.

  } else {

  var linkBackground = "#dddddd";
  var linkBackgroundHighlight = "#00cccc";

  if (is_ie4up) {
      if ((currLink != "") && (currLink != id)) {
          document.all(currLink).style.background = linkBackground;   // First de-highlight the highlighted current link, if any.
      }
      currLink = id;                                                  // Used next time to de-highlight this link
      document.all(id).style.background = linkBackgroundHighlight;    // Highlight the new current link.

  } else                                                              // The same for NN6.

  if ((!is_ie) && (document.getElementById && document.body.style)) { // Non-sniffer test for NN6/standards-compliant browsers.
      if ((currLink != "") && (currLink != id)) {
          document.getElementById(currLink).style.background = linkBackground;
      }
      currLink = id;
      document.getElementById(id).style.background = linkBackgroundHighlight;
  }
  }
}
// Highlight current sub-/sub-sub-menu link; don't change main sub-menu link.
function highlightSubLink(id) { // Takes the ID of a text block (an href link, for example, to constrain width of the highlight effect)
  if (is_nav4) { return;  // No-op for NN4.

  } else {

  var sublinkBackground = "#777777";
  var sublinkBackgroundHighlight = "#555555";

  if (is_ie4up) {
      if ((currSubLink != "") && (currSubLink != id)) {
          document.all(currSubLink).style.background = sublinkBackground;   // First de-highlight the highlighted current link, if any.
      }
      currSubLink = id;
      document.all(id).style.background = sublinkBackgroundHighlight;       // Highlight the sub-/sub-sub-link.

  } else                                                                    // The same for NN6.

  if ((!is_ie) && (document.getElementById && document.body.style)) {       // Non-sniffer test for NN6/standards-compliant browsers.
      if ((currSubLink != "") && (currSubLink != id)) {
          document.getElementById(currSubLink).style.background = sublinkBackground;
      }
      currSubLink = id;
      document.getElementById(id).style.background = sublinkBackgroundHighlight;
  }
  }
}

function unhighlightSubLink(id) { // Takes the ID of a text block (an href link, for example, to constrain width of the highlight effect)
if (is_nav4) { return; // No-op for NN4.
} else {
  if ((is_ie4up) && (currSubLink != "")) {
          document.all(id).style.background = "#aaaaaa"; // De-highlight the current sub-/sub-sub-link, if any.
          document.all(id).style.color = "#000000";      // Use same color as in stylesheet.
          currSubLink = "";

  } else                                                              // The same for NN6.
  if ((!is_ie) && (document.getElementById && document.body.style)) { // Non-sniffer test for NN6/standards-compliant browsers.
      document.getElementById(id).style.background = "#cccccc";
      document.getElementById(id).style.color = "#00cccc";
      currSubLink = "";
  }
}
}

function hideDiv(id) {                         // Hide a named div.
if (is_nav4) { return; }                       // No-op for NN4.

  if (is_ie4up) {
      document.all(id).style.display = "none";
  } else
  if (id) {
  if ((!is_ie) && (document.getElementById && document.body.style)) { // Non-sniffer test for NN6/'standards-compliant' browsers.
//      alert("ID: " + id);
      document.getElementById(id).style.display = "none";
  }
  }
}

function showDivGeneric(id) {                  // Show a named div.
  if (is_nav4) { return; }                       // No-op for NN4.

  if (is_ie4up) {
      document.all(id).style.display = "block";  // Show the selected div.
  } else if ((!is_ie) && (document.getElementById && document.body.style)) { // Non-sniffer test for NN6/standards-compliant browsers.
      document.getElementById(id).style.display = "block";
  }
}

function showDiv(id) {                         // Hide, then show a named div.
if (is_nav4) { return; }                       // No-op for NN4.

  hideDiv(currSubSubMenu);                   // First, hide a sub-sub-menu if one is now visible.
  closeTheArrow(); 
  currSubSubMenu = "introSubSubMenu";        // Makes this div hide-able by other menu functions.

  hideDiv(currSubMenu);                      // Then, hide a sub-div if one is now visible. [Only one sub-menu max. may be visible at a time.]
  currSubMenu = id;                          // Used next time to hide this div.

  if (is_ie4up) {
    document.all(id).style.display = "block";  // Show the selected div.
  } else                                       // The same for NN6/standards-compliant browsers.
  if ((!is_ie) && (document.getElementById && document.body.style)) { // Non-sniffer test for NN6/standards-compliant browsers.
    document.getElementById(id).style.display = "block";
  }
}

function toggleBlockDisplay(blockID) {         // Toggles blockID's display attribute between 'display" and 'none'.
  if (is_nav4) { return; } // No-op for NN4.

  if (is_ie4up) {
    if (document.all(blockID).style.display == "none") {
       (document.all(blockID).style.display = "block");
    } else {
       (document.all(blockID).style.display = "none");
    }
  }
  if ((!is_ie) && (document.getElementById && document.body.style)) { // Non-sniffer test for NN6/standards-compliant browsers.
    if (document.getElementById(blockID).style.display == "none") {
        document.getElementById(blockID).style.display = "block";
    } else {
        document.getElementById(blockID).style.display = "none";
    }
  }
}


// Reveal images based onMouseOver link that specifies image name & new image's url.
function swap(imageName,url) {
  if (document.images) {
     (document.images[imageName].src = url);
  }
}

function toggleSwap(arrowID) {           // Toggles between two states of an image swap, used here for sub-menu arrows.

  if (is_nav4) { return; } // No-op for NN4.

  if (is_ie4up) {
      if (document.all(arrowID).src ==  menuArrows[0].src) {
          swap(arrowID,menuArrows[1].src);
//          currOpenedArrow = arrowID;
      } else {
          swap(arrowID,menuArrows[0].src);
      }
  }
  if ((!is_ie) && (document.getElementById)) { // Non-sniffer test for NN6/'standards-compliant' browsers.
    if (document.images[arrowID].src.indexOf(menuArrows[0].src) != -1) {
       swap(arrowID,menuArrows[1].src);
//       currOpenedArrow = arrowID;
    } else {
       swap(arrowID,menuArrows[0].src);
    }
  }
}


function activateMenu(itemLinkName,subMenuID) {  // _Display_ of sub-sub-menus is handled separately (with a simple showDiv).

  if (is_nav4) { return; }               // No-op for NN4.

    hideDiv(currSubSubMenu);             // First, hide a sub-sub-menu if one is now visible. [because any new activateMenu() requires closing any open sub-sub-menu]
    closeTheArrow();
    currSubSubMenu = "introSubSubMenu";  // Makes this div hide-able by other menu functions. [the variable must be set to _something_, but this doesn't make introSubSubMenu active or visible]

    if (subMenuID != currSubMenu) {      // Do nothing unless subMenuID is different from the current subMenu.
        hideDiv(currSubMenu);            // If they are different, hide a sub-menu if one is now visible.
    }

    highlight(itemLinkName);

    if (subMenuID != '') {
        if ((is_ie4up) && (is_mac)) {
             (document.all(subMenuID).style.top = 5);
             (document.all(subMenuID).style.left = 126);
        }
        showDiv(subMenuID)               // Show the associated submenu, if any.
        currSubMenu = subMenuID;         // Used next time to hide this div.
    }
}

function toggleSubSubMenu(subSubMenuID) {
  if (is_nav4) { return; } // No-op for NN4.

  if (currSubSubMenu != subSubMenuID) {  // If subSubMenuID is not the current sub-sub-menu:
      hideDiv(currSubSubMenu);
      closeTheArrow();
      currSubSubMenu = subSubMenuID;
  }
  toggleBlockDisplay(subSubMenuID);
}


// Initialize caption to default, displayed caption-containing DIV for before-and-after images.
var currPatientBeforeImageCaption = 'patientAbeforeCaption';
var currPatientAfterImageCaption  = 'patientAafterCaption';

function swapBeforeAndAfter(patientID,beforeArrayElement,afterArrayElement) { // Simple image swap for NN4, but manages DIVs for other browsers.
	if (!is_nav4) { 
	  hideDiv(currPatientBeforeImageCaption);
	  hideDiv(currPatientAfterImageCaption);
	  currPatientBeforeImageCaption = 'patient'+patientID+'beforeCaption';
	  currPatientAfterImageCaption  = 'patient'+patientID+'afterCaption';
	  showDivGeneric('patientBeforeImage');
	  showDivGeneric('patientAfterImage');
	  showDivGeneric('patient'+patientID+'beforeCaption');
	  showDivGeneric('patient'+patientID+'afterCaption');
	}
	swap('patientBefore',beforeArrayElement.src); 
	swap('patientAfter',afterArrayElement.src);
	currPatientBeforeImage = beforeArrayElement.src // Initialize these two vars on pages that call NN4 function 'hideImage()'
	currPatientAfterImage  =  afterArrayElement.src
	}

