 
 (defn on-popstate [e]
   (if (.-state e)
-    (swap! selected-time #(.-time e))))
+    (reset! selected-time (.-time e))))
 
 (defn on-datetime-change []
   (let [date (.datepicker ($ "#datepicker") "getDate")
         new-time (doto date
                     (.setMinutes (.getMinutes @selected-time))
                     (.setHours (.getHours @selected-time)))]
-    (swap! selected-time #(new-time))))
+    (reset! selected-time new-time)))
 
 (defn click-toggle-meridian []
   (let [hours (+ (get-hours) 12)

  (:require-macros [hiccups.core :as hiccups])
  (:require
    [hiccups.runtime :as hiccupsrt]
    [clojure.walk]))

;;------------------------------------------------------------------------------
;; Atoms

;;------------------------------------------------------------------------------

(defn init-snapshot-list []
  (->> (.-SNAPSHOT_LIST js/window) ; server injected to this in a <script>
        (js->clj)
        (clojure.walk/keywordize-keys)
        (reset! snapshot-list)))

(defn init-snapshot-index []
  (let [image (attr ($ "#currentSnapshot") "src")
        starting-index (first (keep-indexed #(if (= image (:image %2)) %1) @snapshot-list))]
    (reset! snapshot-index
      (if (pos? starting-index)
        starting-index
        0))))

(defn init []
  (html ($ "#timepickerContainer") (build-timepicker))
  (init-snapshot-list)
  (init-snapshot-index)
  (sync-time-with-snapshot!)
