 
 (defn init-snapshot-list []
   (->> (.-SNAPSHOT_LIST js/window) ; server injected to this in a <script>
-       (js->clj)
-       (clojure.walk/keywordize-keys)
+       ; (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))]
+        starting-index (first (keep-indexed #(if (= image (.-image %2)) %1) @snapshot-list))]
     (reset! snapshot-index
       (if (pos? starting-index)
         starting-index

  (* hours 3600000))

(defn sync-time-with-snapshot! []
  (reset! selected-time (:time (@snapshot-list @snapshot-index))))

; TODO: This could be improved. Probably need to rethink my data model
(defn show-closest-snapshot! []
  (let [timestamp @selected-time
        earlier-index (first (keep-indexed #(if (>= timestamp (:time %2)) %1) @snapshot-list))
        later-index (max (dec earlier-index) 0)
        later (:time (@snapshot-list later-index))
        earlier (:time (@snapshot-list earlier-index))
        display-index (if (< (- later timestamp) (- timestamp earlier))
                        later-index
                        earlier-index)]

(add-watch selected-time :_ on-selected-time-change)

(defn on-snapshot-index-change [_ _ _ new-index]
  (let [snapshot (nth @snapshot-list new-index)
        timestamp (.-time snapshot)
        datetime (js/Date. timestamp)
        image (.-image snapshot)
        time-display (str (.toDateString datetime) " " (.toLocaleTimeString datetime))]
    (attr ($ "#currentSnapshot") "src" image)
    (text ($ "#imageDateTime") time-display)
