﻿
var ss = {
  smoothScroll: function(e) 
  {
    try
    {
    
        anchor = e.substr(1);    
        destinationLink = document.getElementById( anchor )
      
        var destx = destinationLink.offsetLeft; 
        var desty = destinationLink.offsetTop;
        var thisNode = destinationLink;
        while (thisNode.offsetParent && 
              (thisNode.offsetParent != document.body)) {
          thisNode = thisNode.offsetParent;
          destx += thisNode.offsetLeft;
          desty += thisNode.offsetTop;
        }
      
        clearInterval(ss.INTERVAL);
        cypos = ss.getCurrentYPos();
      
        ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
        ss.INTERVAL =
        setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
      
        if (window.event) {
          window.event.cancelBubble = true;
          window.event.returnValue = false;
        }
        if (e && e.preventDefault && e.stopPropagation) {
          e.preventDefault();
          e.stopPropagation();
        }    
    
    }
    catch( e )
    {
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      window.scrollTo(0,dest);
      clearInterval(ss.INTERVAL);
      location.hash = anchor;
    }
  },

  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;
  }
}

ss.STEPS = 25;

if( typeof(Sys) != "undefined" && typeof(Sys.Application) != "undefined" )
{
  Sys.Application.notifyScriptLoaded();
}

