     if(!SetActiveElem(id)) {
       SetActiveElem('_main');
     }
+}
+
+function ScrollToY(y)
+{
+  if(window.scrollY !== y) {
+    window.scrollTo(window.scrollX, y);
+  }
 }
 
 function CenterElem(el)

  return ret;
}


function SetActive()
{
    var raw = window.location.hash.substr(1);

            newY = window.scrollY +
                   elRect.top -
                   (docEl.clientHeight - elHeight) / 2;
        ScrollToY(newY);
    }
}

function DoScroll()
{
  window.setTimeout(
    function() {
      if(document.kj.centeractive) {
        CenterElem(FindElem(activeId));
      }
      if(document.kj.scrolltop) {
        ScrollToY(0);
      }
    }, 0);
}

SetActive();
DoScroll();

window.addEventListener('hashchange', function(e) {
  SetActive();
  DoScroll();
});

domready(function() {
  SetActive();
  DoScroll();
});

})(document, window);
