(function($){
$(function(){
    $('a[href*=#],area[href*=#]').each(function() {
        var to = 0;
        if($(this).attr("href") == "#") {
            to = 0;
            $(this).attr("href", "javascript:void(0);");
        }
        else {
            var target = $("a[name=" + this.hash.substr(1) + "]");
            if(target.length > 0) {
                to = target.offset().top;
            }
            else { return; }
        }
        $(this).click(function() {
            $('html,body').animate({scrollTop: to}, 'fast');
        });
    });
    
    var a = window.location.href.split("#");a.shift();a=a.join("#");
    if(a) {
        $(document).scrollTop(0);
        var target = $("a[name=" + a + "]");
        if(target.length > 0) {
            $('html,body').animate({scrollTop: target.offset().top}, 'fast');
        }
    }
    
    $('a[href*=#],area[href*=#]').each(function() {
        var hr = $(this).attr("href");
        if(hr.length > 0 && hr.charAt(hr.length - 1) != "#") {
            $("a[name=" + this.hash.substr(1) + "]").remove();
        }
    });
});
})(jQuery);

