(function($){
    $.fn.scrollToAnchor = function(speed) {
        if (!speed) speed = 800;
        return this.each(function(index){
            var a = $(this);
            a.click(function(e){
                var u = this.href,
                    a = u.split("#");
          
                if (a.length > 1){
                   if (a[1].length > 0) {
                      var t = $("#"+a[1]);            
                      if (t.length == 1){
                          $('html,body').animate({scrollTop:t.offset().top},speed);
                          e.preventDefault();
                      }
                   } else { 
                     	$('html,body').animate({scrollTop:0},speed);
                      e.preventDefault();
                  }
                };
            });
        });
    }  
})(jQuery);


/*
function _scrollToAnchor(){
  this.speed = 800;
}
_scrollToAnchor.prototype = {
  init : function(){
    var self = this;
    $("a").click(function(e){
      var u = this.href,
          a = u.split("#");

      if (a.length > 1 && a[1].length > 0){
        var t = $("#"+a[1]);            
        if (t.length == 1){
            $('html,body').animate({scrollTop:t.offset().top},self.speed);
            e.preventDefault();
        }
      }
    });
  }
}
var scrollToAnchor = new _scrollToAnchor();
$(function(){
  scrollToAnchor.init();
});

*/
