var ss = {
  
  fixallLinks: function()
     {
      // Get a list of all links in the page
      var a_links = document.getElementsByTagName('a');
      // Walk through the list
      for (var i_indx=0;i_indx<a_links.length;i_indx++)
          {
          var o_link = a_links[i_indx];
          if ((o_link.href && o_link.href.indexOf('#') != -1) &&
             ( (o_link.pathname == location.pathname) ||
	     ('/'+o_link.pathname == location.pathname) ) && 
             (o_link.search == location.search))
              {
              // If the link is internal to the page (begins in #)
              // then attach the smoothScroll function as an onclick
              // event handler
              ss.addEvent(o_link,'click',ss.smoothScroll);
              }
          if (o_link.name == "boatyards")
              {
              i_frst = o_link.offsetTop;
              var o_node = o_link;
              while (o_node.offsetParent && (o_node.offsetParent != document.body))
                  {
                  o_node = o_node.offsetParent;
                  i_frst += o_node.offsetTop;
                  }
              document.getElementById('anchors').style.top = i_frst;
              }
          if (o_link.name == "waterways")
              {
              i_last = o_link.offsetTop;
              var o_node = o_link;
              while (o_node.offsetParent && (o_node.offsetParent != document.body))
                  {
                  o_node = o_node.offsetParent;
                  i_last += o_node.offsetTop;
                  }
              }
          }
      },

  smoothScroll: function(e_vent) 
     {
      // This is an event handler; get the clicked on element,
      // in a cross-browser fashion
      if (window.event)
         {
          o_trgt = window.event.srcElement;
          }
      else
          {
          if (e_vent)
              {
              o_trgt = e_vent.target;
              }
          else
              {
              return;
              }
          }
      // Make sure that the target is an element, not a text node
      // within an element
      if (o_trgt.nodeType == 3)
          {
          o_trgt = o_trgt.parentNode;
          }
      // Paranoia; check this is an A tag
      if (o_trgt.nodeName.toLowerCase() != 'a')
          {
          return;
          }
      // Find the <a name> tag corresponding to this href
      // First strip off the hash (first character)
      o_anch = o_trgt.hash.substr(1);
      // Now loop all A tags until we find one with that name
      var a_links = document.getElementsByTagName('a');
      var o_dstn = null;
      for (var i_indx=0;i_indx<a_links.length;i_indx++)
         {
          var o_link = a_links[i_indx];
          if (o_link.name && (o_link.name == o_anch))
              {
              o_dstn = o_link;
              break;
              }
          }
      // If we didn't find a destination, give up and let the browser do
      // its thing
      if (!o_dstn)
          {
          return true;
          }
      // Find the destination's position
      var i_dstx = o_dstn.offsetLeft;
     var i_dsty = o_dstn.offsetTop;
      var o_node = o_dstn;
      while (o_node.offsetParent && (o_node.offsetParent != document.body))
          {
          o_node = o_node.offsetParent;
          i_dstx += o_node.offsetLeft;
          i_dsty += o_node.offsetTop;
          }
      // Stop any current scrolling
      clearInterval(ss.INTERVAL);
      i_cury = ss.getCurrentYPos();
      if (i_dsty > i_cury)
          {
          i_step = 10;
          }
      else
          {
          i_step = -10;
          }
      ss.INTERVAL = setInterval('ss.scrollWindow('+i_step+','+i_dsty+',"'+o_anch+'")',10);
      // And stop the actual click happening
      if (window.event)
          {
          window.event.cancelBubble = true;
          window.event.returnValue = false;
          }
      if (e_vent && e_vent.preventDefault && e_vent.stopPropagation)
          {
          e_vent.preventDefault();
          e_vent.stopPropagation();
          }
      },

  scrollWindow: function(scramount,dest,anchor)
      {
      b_arrived = false;
      i_oldy = ss.getCurrentYPos();
      if (scramount > 0)
          {
          if (i_oldy + scramount > dest)
              {
              window.scrollTo(0,dest);
              b_arrived = true;
              }
          else
              {
              window.scrollTo(0,i_oldy + scramount);
              }
          }
      else
          {
          if (i_oldy + scramount < dest)
              {
              window.scrollTo(0,dest);
              b_arrived = true;
              }
          else
              {
              window.scrollTo(0,i_oldy + scramount);
              }
          }
      i_newy = ss.getCurrentYPos();
      if (b_arrived || (i_oldy == i_newy))
          {
          // cancel the repeating timer
          clearInterval(ss.INTERVAL);
          // and jump to the link directly so the URL's right
          location.hash = anchor;
          }
      // Move the Anchor list
      if (i_newy >= i_frst && i_newy <= i_last)
          {
          document.getElementById('anchors').style.top = i_newy;
          }
      },

  getCurrentYPos: function() 
      {
      if (document.body && document.body.scrollTop)
          {
          return document.body.scrollTop;
          }
      if (document.documentElement && document.documentElement.scrollTop)
          {
          return document.documentElement.scrollTop;
          }
      if (window.pageYOffset)
          {
          return window.pageYOffset;
          }
      return 0;
      },

  addEvent: function(elm, evType, fn, useCapture)
      {
      // addEvent and removeEvent
      // cross-browser event handling for IE5+,  NS6 and Mozilla
      if (elm.addEventListener)
          {
          elm.addEventListener(evType, fn, useCapture);
          return true;
          }
      else
          {
          if (elm.attachEvent)
              {
              var o_rtrn = elm.attachEvent("on"+evType, fn);
              return o_rtrn;
              }
          else
             {
              alert("Handler could not be removed");
              }
          }
      }
  }

var i_frst = 0;
var i_last = 0;

ss.addEvent(window,"load",ss.fixallLinks);
