// registration code from Rhino p434:
if (window.addEventListener)
   window.addEventListener("load", initialize, false);
else if (window.attachEvent)
   window.attachEvent("onload", initialize);
else
   window.onload=initialize;

// extract filename from document URL:
var url = document.URL;
var result = url.match (/[\/\\]\w+(?=\.(htm|php))/i); // was: url.match (/[\/\\]\w+(?=\.(htm|php)$)/i);
var fileName;
if (result == null)
   fileName = "index";
else
   fileName = result[0].substr(1);

// temporarily hide header table of index.htm to prepare for animation effect:
if (fileName == "index")
   {
   document.write ('<style type="text/css"> table#header {visibility:hidden;} </style>');
   }

function initialize ()
   {
   // header animation on home page: move header elements in from 2 directions
   if (fileName == "index")
      {
      var positionInterval = 15;    // interval between animations in milliseconds
      var positionDelta = 4;        // amount to change position per animation
      var offset = -160;            // initial offset of elements
      var logoImg = document.getElementById("logoImage");
      var nameSpan = document.getElementById("nameSpan"); 
      var linksTable = document.getElementById ("links");
      var positionIntervalID;
      var firstPass = true;

      // to block animation when coming from a page on same site, see Rhino p302
      logoImg.style.position = "relative";
      nameSpan.style.position = "relative";
      linksTable.style.position = "relative";
      positionIntervalID = setInterval (animateElementPositions, positionInterval);
      }
   function animateElementPositions ()
      {
      if (offset >= 0)
         {
         logoImg.style.left = "auto";   
         nameSpan.style.top = "auto";   
         linksTable.style.top = "auto";   
         window.clearInterval (positionIntervalID);
         return;
         }
      logoImg.style.left = offset + "px";
      nameSpan.style.top = offset + "px";
      linksTable.style.top = offset + "px";
      if (firstPass)
         {
         document.getElementById("header").style.visibility = "visible";
         firstPass = false;
         }
      offset += positionDelta;
      }

   // initialize popup links:
   var popupLinks = document.getElementsByName ("popup");
   for (var i = 0; i < popupLinks.length; ++i)
      popupLinks[i].onclick = function () 
         {
         window.open(this.href, "", "resizable=yes, scrollbars=yes");
         return false;
         };

   // initialize rollover images:
   var rolloverImages = document.getElementsByName ("rollover");
   for (i = 0; i < rolloverImages.length; ++i)
      {
      var imgURL = rolloverImages[i].src;
      var imgURLAlt = imgURL.substring(0, imgURL.lastIndexOf(".")) + "_alt" + imgURL.substring(imgURL.lastIndexOf("."));
      (new Image()).src = imgURLAlt;
      setRollover (rolloverImages[i], imgURL, imgURLAlt);
      }
   function setRollover (img, imgURL, imgURLAlt)
      {
      img.onmouseover = function ()
         {
         img.src = imgURLAlt;
         };
      img.onmouseout = function ()
         {
         img.src = imgURL;
         };
      }

   // code for "An Ajax Weather Widget" demo in Demos.htm:
   if (fileName == "Demos")
      {
      updateWeather ();
      setInterval (updateWeather, 300000);  // update weather info every 5 minutes
      }

   }  // end 'initialize'