$(document).ready(function(){
	/* When menu item is clicked, scroll down to target with -64px offset. 
	 * Target is decided according to h1[name='xxx'] instead of id. 
	 */
	$('a[href^="#"]').on('click',function (e) {
	    e.preventDefault();
	    var target = (this.hash + ', h1[name="' + this.hash.substr(1) + '"]'),
	    $target = $(target);
	    $('html, body').stop().animate({
	        'scrollTop': $target.offset().top -64
	    }, 400, 'swing', function () {
	        window.location.hash = target;
			removeHash();
	    });
	});
});

/* Function removes hash on URL */
function removeHash() { 
  if(window.location.hash) 
  {
    var scrollV, scrollH, loc = window.location;
    if ("pushState" in history)
        history.pushState("", document.title, loc.pathname + loc.search);
    else {
        // Prevent scrolling by storing the page's current scroll offset
        scrollV = document.body.scrollTop;
        scrollH = document.body.scrollLeft; 
        loc.hash = "";

        // Restore the scroll offset, should be flicker free
        document.body.scrollTop = scrollV;
        document.body.scrollLeft = scrollH;
    }
  }
}