     [client.pages.spectate :as spectate-page]
     [client.util :as util]))
 
+(def function? js/goog.isFunction)
+
 ;;------------------------------------------------------------------------------
 ;; Routes
 ;;------------------------------------------------------------------------------

(defn- on-hash-change []
  (let [new-route (.replace (aget js/document "location" "hash") #"^#" "")
        page (get routes new-route)
        init-fn (first page)
        cleanup-fn (second page)]
    (if-not (or page init-fn)
      (aset js/document "location" "hash" default-route)
      (do
        ;; run cleanup function from last page
        (if (and @previous-page-cleanup-fn
                 (js/goog.isFunction @previous-page-cleanup-fn))
          (@previous-page-cleanup-fn))

        ;; run init function for the new page

  "/play2" [play-page/init-battle2! play-page/cleanup!]

  ;; redirects - where is my HTTP 301? :)
  "/dashboard" #(aset js/document "location" "hash" "/spectate")
  })

(def previous-page-cleanup-fn (atom nil))
