           (.html main-text-element new-main-text)
           (.fadeIn main-text-element "fast"))))))))
 
-(defn current-page-relative-href []
+(defn current-page-relative-href
+  "Extract the relative URL of the current page.
+   e.g. (current-page-relative-href) on
+   http://web.mit.edu/rahulraj/www/index.html
+   returns 'index.html'."
+  []
   (let [location (.location js/window)
         url location/href
         parts (.split url "/")]
     (last parts)))
 
-(defn parent [jquery-object]
+(defn parent
+  "Get the parent of a JQuery object. Similar to html,
+   puts a facade around a no-argument method."
+  [jquery-object]
   (. jquery-object (parent)))
 
-(defn restyle-anchors [clicked-anchor]
+(defn restyle-anchors
+  "On any given page, the current page in the nav area
+   should be bolded and not an anchor, while the remaining
+   items in nav are anchors. When a new page is loaded, this
+   function updates the nav list items to reflect this."
+  [clicked-anchor]
   (let [current-page-href (current-page-relative-href)
         current-page-anchor (js/jQuery (str "<a href=" current-page-href ">"))
         current-page-list-item (js/jQuery "#currentPage")

  (. jquery-object (html)))

(defn main-text-from-load-container
  [container]
  (-> container
    (.find main-text-id)
    (html)))

(defn load-content [anchor]
  (let [anchors-href (.attr anchor "href")
        to-load (str anchors-href " " main-text-id)
        load-container (js/jQuery "<span>")

    (site/removeEvents)
    (site/addHoverEventsToAnchors))))

(defn update-history
  "Update the history so the URL is still valid,
   given the clicked anchor (which is now Ajaxy)
   TODO make the back button work too."
  [clicked-anchor]
  (let [new-href (.attr clicked-anchor "href")]
    (.pushState js/history {} "State" new-href)))

(defn ^:export on-anchor-click
  "Called on click of an anchor (the anchor is passed in)"
  [anchor]
  ; TODO Use the History API to make back/forward work again.
  (doto anchor
    (load-content)
    (restyle-anchors)
    (update-history)))

(defn ^:export main
  "Entry point for the Clojurescript, to be called on load"
