     }
 }
 
+function FindElem(id)
+{
+    return id === null ? null : document.getElementById(id);
+}
+
 function SetHilight()
 {
     var el;
-    if(document.lastElem) {
-        el = document.getElementById(document.lastElem);
-        RemoveHilite(el);
+    el = FindElem(lastElem);
+    RemoveHilite(el);
+
+    var id = '_' + window.location.hash.substr(1);
+    el = FindElem(id);
+    if(el) {
+        lastElem = id;
+        AddHilite(el);
+    } else {
+        lastElem = null;
     }
-
-    var id = window.location.hash.substr(1);
-    el = document.getElementById(id);
+}
+
+function CenterElem(el)
+{
     if(el) {
-        document.lastElem = id;
-        AddHilite(el);
+        var elRect = el.getBoundingClientRect(),
+            elHeight = elRect.bottom - elRect.top,
+            docEl = document.documentElement,
+            newY = window.scrollY +
+                   elRect.top -
+                   (docEl.clientHeight - elHeight) / 2;
+        window.scrollTo(window.scrollX, newY);
     }
 }
 
-document.addEventListener('DOMContentLoaded', function(e) {
-    SetHilight();
-    window.addEventListener('hashchange', function(e) {
-        SetHilight();
-    });
+window.addEventListener('hashchange', function(e) {
+  SetHilight();
 });
+
+window.addEventListener('load', function() {
+  SetHilight();
+  window.setTimeout(function() { CenterElem(FindElem(lastElem)); }, 1);
+});
+
+})(document, window);
 
 // Google Analytics
 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){


(defn js []
"// NOTE: Experimental
document.lastElem = null;

function RemoveHilite(el) {
    if(el) {

    (rel-url book-id chap-num chap-cnt)))

(defn toc-book [b]
  [:p.tocp {:id (str "_" (book-elem-id (:id b)))}
    [:span.chapter (book-name (:id b))]
    " "
    (->> (:chapters b)
