/* 
*** Please do not use a local version of this script ***

   Name          : menu2.js 

   Author        : Derek Hardy - hardyd@visto.com

   Description   : Navigation script for virgin one account internet sites. Uses layers to display
                   individual menu palettes and allows the user to scroll through without affecting
                   the content window until they select an option.

   Usage         : This script can be used in one of two ways, please see note below about frames

                   1) If the HTML pages use standard layer names, i.e. menuDivx (where x is the hierarchy number)
                      for the menu layers and backarrows and forwardarrows for the scrolling buttons;
                      and uses standard image names for the scrolling buttons (backArrowsImg and forwardArrowsImg)
                      then this script can be used without modification.

                   2) If the HTML doesn't use standard names, then place the 5 page specific variables - layerPrefix,
                      previousImage, nextImage, previousArrowsLayer, nextArrowsLayer into the page and assign the
                      correct values then reference the script in the usual way.

   Notes         : FRAMES - Please note if this script is to be used within a frameset, then please ensure that the frame is called "navigation"

   Compatibility : Enter a record here if you are able to test it on other versions, email me (hardyd@visto.com) with any results/issues.

                                       Platform    Result
                   Netscape
                      4.75             PC          Tested OK

                   Internet Explorer
                      5.50.4134.0600   PC          Tested OK
		      
		   Netscape            
		      4.75             Mac         Tested OK
		   
		   Internet Explorer   
		      5.0.2022         Mac         Tested OK
		      
	           Mozilla M18/Netscape 6        
		     (Gecko 20001108)  PC          Tested OK
		     (Gecko 20001108)  Mac         Tested OK


		      
		      
  Change History

   Version   Date        Author        Summary
   ------------------------------------------------------------------------------------------------
   1.0       23-11-00    Derek Hardy   Created.
   1.1       05-12-00    Derek Hardy   Made modifications to allow script to work within a frameset.
   1.2       11-12-00    Mat Brown     Added whitebox layer for home menu level - NOT PC/Moz TESTED!
   1.3       13-12-00    Derek Hardy   Added menu level icons.
*/
   //
   // Comment the next 5 lines out if using page specific version
   //
   var layerPrefix         = "menuDIV";              // Prefix for layers that contain the menus
   var previousImage       = "backArrowsImg";        // Image that contains the scroll previous buttons
   var nextImage           = "forwardArrowsImg";     // Image that contains the scroll next buttons
   var previousArrowsLayer = "backarrows";           // Layer that contains the backward arrows
   var nextArrowsLayer     = "forwardarrows";        // Layer that contains the forward arrows
   var levelIcon           = "menuLevelImg";         // Image that contains the menu level icon
   var navFrame            = "navigation";           // Frame name that contains the navigation HTML page
   var levelLayer          = "menuLevel";            // Layer that contains the menu level icon
   var currentMenu = 0;                              // menu currently displayed
   var lyr = new Array();                            // Create an array to hold the menu layers

   var levelImages = new Array();                    // Array to hold level icon images

   var fr = (top.location != location) ? 1 : 0;      // Page in frames indicator
   var IE = (document.all) ? 1 : 0;                  // Internet Explorer indicator
   var NS6 = (document.getElementById) ? 1 : 0;      // Netscape 6 indicator

   if (!IE && !NS6)
   {
      if (fr)
      {
         NS = (parent.document.layers) ? 1 : 0;         // Netscape indicator
      }
      else
      {
         NS = (document.layers) ? 1 : 0;                // Netscape indicator
      }
   }
   else
   {
      NS = 0;
   }

   if (!IE && !NS6)
   {
      if (fr)
      {
         img = (parent.document.images) ? 1 : 0;
      }
      else
      {
         img = (document.images) ? 1 : 0;
      }
   }
   else
   {
      img = (document.images) ? 1 : 0;
   }

   if (img)
   {
      // Set up the forwards and backwards arrows
      scrollPreviousActive   = new Image (); scrollPreviousActive.src   = "./assets/back-arrows.gif";
      scrollPreviousInactive = new Image (); scrollPreviousInactive.src = "./assets/back-arrows-grey.gif";
      scrollNextActive       = new Image (); scrollNextActive.src       = "./assets/forward-arrows.gif";
      scrollNextInactive     = new Image (); scrollNextInactive.src     = "./assets/forward-arrows-grey.gif";
   }

   function dhLayer (id)
   {
      if (NS)
      {
         if (fr)
         {
            this.element = parent.frames[navFrame].document[id];
         }
         else
         {
            this.element = document[id];
         }
      }
      else if (IE)
      {
         this.element = document.all[id].style;
      }
      else if (NS6)
      {
         this.element = document.getElementById(id).style;
      }
   }

   function showLayer()
   {
      this.element.visibility = (NS) ? "show" : "visible";
   }

   function hideLayer()
   {
      this.element.visibility = (NS) ? "hide" : "hidden";
   }

   function start()
   {
      dhLayer.prototype.show = showLayer;
      dhLayer.prototype.hide = hideLayer;

      counter = 0;

      totalCounter = 0;

      if (NS)
      {
         if (fr)
         {
            totalCounter = parent.frames[navFrame].document.layers.length;
         }
         else
         {
            totalCounter = document.layers.length;
         }
      }
      else if (IE)
      {
         totalCounter = document.all.length;
      }
      else if (NS6)
      {
         divArray = document.getElementsByTagName("DIV");
         totalCounter = divArray.length;
      }

      for (i = 0; i < totalCounter ; i++)
      {
         if (NS)
         {
            if (fr)
            {
               pos = parent.frames[navFrame].document.layers[i].id.indexOf("menuDIV");
            }
            else
            {
               pos = document.layers[i].id.indexOf("menuDIV");
            }
         }
         else if (IE)
         {
            pos = document.all[i].id.indexOf("menuDIV");
         }
         else if (NS6)
         {
            pos = divArray[i].id.indexOf("menuDIV");
         }

         if (pos != -1)
         {
            if (NS)
            {
               if (fr)
               {
                  lyr[counter] = new dhLayer(parent.frames[navFrame].document.layers[i].id);
               }
               else
               {
                  lyr[counter] = new dhLayer(document.layers[i].id);
               }
            }
            else if (IE)
            {
               lyr[counter] = new dhLayer(document.all[i].id);
            }
            else if (NS6)
            {
               lyr[counter] = new dhLayer(divArray[i].id);
            }

            counter++;
         }
      }

      for (i = 0; i < counter ; i++)
      {
         levelImages[i] = new Image ();
  
         if (i==0)
         {
            levelImages[i].src = "./assets/home-dot-location.gif";
         }
         else
         {
            levelImages[i].src = "./assets/"+i+"-dot-location.gif";
         }
      }
   }
      
   function showPreviousButtons()
   {
      if (NS)
      {
         if (fr)
         {
            parent.frames[navFrame].document.layers[previousArrowsLayer].document.images[previousImage].src = scrollPreviousActive.src;
         }
         else
         {
            document.layers[previousArrowsLayer].document[previousImage].src = scrollPreviousActive.src;
         }
      }
      else
      {
         document[previousImage].src = scrollPreviousActive.src;
      }
   }

   function hidePreviousButtons()
   {
      if (NS)
      {
         if (fr)
         {
            parent.frames[navFrame].document.layers[previousArrowsLayer].document.images[previousImage].src = scrollPreviousInactive.src;
         }
         else
         {
            document.layers[previousArrowsLayer].document[previousImage].src = scrollPreviousInactive.src;
         }
      }
      else
      {
         document[previousImage].src = scrollPreviousInactive.src;
      }
   }

   function showNextButtons()
   {
      if (NS)
      {
         if (fr)
         {
            parent.frames[navFrame].document.layers[nextArrowsLayer].document[nextImage].src = scrollNextActive.src;
         }
         else
         {
            document.layers[nextArrowsLayer].document[nextImage].src = scrollNextActive.src;
         }
      }
      else
      {
         document[nextImage].src = scrollNextActive.src;
      }
   }

   function hideNextButtons()
   {
     if (NS)
     {
        if (fr)
        {
           parent.frames[navFrame].document.layers[nextArrowsLayer].document[nextImage].src = scrollNextInactive.src;
        }
        else
        {
           document.layers[nextArrowsLayer].document[nextImage].src = scrollNextInactive.src;
        }
     }
     else
     {
        document[nextImage].src = scrollNextInactive.src;
     }
   }

   //
   // Turn off the visibility attribute for the given menu layer
   function hideMenu (menuNumber)
   {
      lyr[menuNumber].hide();
   }

   //
   // Turn on the visibility attribute for the given menu layer
   function showMenu (menuNumber)
   {
      lyr[menuNumber].show();

      // Set the menuLevel icon
      if (NS)
      {
         if (fr)
         {
            parent.frames[navFrame].document.layers[levelLayer].document[levelIcon].src = levelImages[menuNumber].src;
         }
         else
         {
            document.layers[levelLayer].document[levelIcon].src = levelImages[menuNumber].src;
         }
      }
      else
      {
         document[levelIcon].src = levelImages[menuNumber].src;
      }

      currentMenu = menuNumber;

      if (currentMenu==0)
         hidePreviousButtons();
      else
         showPreviousButtons();

      if (currentMenu==lyr.length-1)
         hideNextButtons();
      else
         showNextButtons();
   }

   //
   // Scroll the menu layers up, hiding the current layer and displaying the next one in the array
   function scrollUp ()
   {
      if (currentMenu < lyr.length-1)
      {
         hideMenu (currentMenu);
         showMenu (currentMenu+1);
         whiteback();
     }
   }

   //
   // Scroll the menu layers down, hiding the current layer and displaying the previous one in the array
   function scrollDown ()
   {
      if (currentMenu>0)
      {
         hideMenu (currentMenu);
         showMenu (currentMenu-1);
         whiteback();
      }
   }

   //
   // Display the starting menu layer
   function showStartMenu ()
   {
      start();

      showMenu (lyr.length-1);
      currentMenu = lyr.length-1;
   }

//
// show whitebox on layer 1 ONLY.

function whiteback()
{
    if (currentMenu>0) {
	MM_showHideLayers('whitebox','','hide');
    }
    
    else {
        MM_showHideLayers('whitebox','','show');
        }
}
