Gentle_Anchors = function() {
  var elt = null; // the current clicked on element

  // Initialization, grabbing all anchors and adding onclick event
  Init = function() {
    var a = document.getElementsByTagName('a'); // got catch'em all!
    var area = document.getElementsByTagName('area');
    var links = new Array(); // combine NodeLists together
    for (var x=0, y=a.length;    x < y; links.push(a[x]), x++);
    for (var x=0, y=area.length; x < y; links.push(area[x]), x++);
    for (var x=0, l=links.length; x < l; x++) {
      if (links[x].href.match(/#[a-zA-Z0-9:\._-]+/)) {
        links[x].onclick = function() { var s = Setup(this.href); return s; };
      }
    }
  };
  // Set things up for the scrolling effect
  Setup = function(href) {
    var hash = href.match(/#([^\?]+)/)[1]; // get id, but not any query string
    // identify destination element
    if (document.getElementById(hash)) { elt=document.getElementById(hash); }
    else { return true; }
    // Find scroll position to destination
    var dest = elt.offsetTop;
    for (var node=elt; node.offsetParent && node.offsetParent != document.body;
         node = node.offsetParent, dest += node.offsetTop);
    // fix for stupid IE
    if (navigator.appName.indexOf("Microsoft") != -1
        && parseFloat(navigator.appVersion.split("MSIE")[1]) < 8.0)
    { dest = elt.offsetTop; }
    // fix for back button
    location.hash = hash;     // jump to destination
    window.scrollTo(0, dest-10);
    return false;
  };

  // Classic append for onload event to avoid overriding
  function AppendOnLoad(fx) { 
    var old = window.onload;
    if (typeof old != 'function') { window.onload = fx; }
    else { window.onload = function() { old(); fx(); }; }
  }
  AppendOnLoad(Init);
}();

