   (on ($ js/document) "keydown" on-keydown)
 
   (-> ($ "body")
+    (on "click" ".timepicker-widget a" (fn [e] (.preventDefault e)))
     (on "click" ".toggle-meridian" click-toggle-meridian)
     (on "click" ".decrement-hour" click-decrement-hour)
     (on "click" ".increment-hour" click-increment-hour)

  "zero pad timepicker digits"
  (goog.string/format "%02d" num))

(defn get-hours []
  (.getHours @selected-time))

(defn get-minutes []
  (.getMinutes @selected-time))

(defn set-hours! [new-hours]
  (swap! selected-time #(doto % (.setHours new-hours))))

(defn set-minutes! [new-mins]
  (swap! selected-time #(doto % (.setMinutes new-mins))))

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

; TODO: This could be improved. Probably need to rethink my data model
(defn show-closest-snapshot! []
  (let [timestamp (.getTime @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))

    (reset! selected-time (.-time e))))

(defn on-datetime-change []
  (let [selected-date (.datepicker ($ "#datepicker") "getDate")
        datetime (js/Date. @selected-time)
        new-time (doto selected-date
                    (.setMinutes (.getMinutes datetime))
                    (.setHours (.getHours datetime)))]
    (println (.toString new-time))
    (reset! selected-time (.getTime new-time))
    (show-closest-snapshot!)))

(defn click-toggle-meridian []
  (let [meridian (val ($ "#meridian"))
        hours (if (= meridian "AM") 12 -12)]
    (swap! selected-time + (hours-to-ms hours))
    (show-closest-snapshot!)))

(defn click-decrement-hour []
  (swap! selected-time - (hours-to-ms 1))
  (show-closest-snapshot!))

(defn click-increment-hour []
  (swap! selected-time + (hours-to-ms 1))
  (show-closest-snapshot!))

(defn click-decrement-Minute []
  (swap! selected-time - (minutes-to-ms 1))
  (show-closest-snapshot!))

(defn click-increment-minute []
  (swap! selected-time + (minutes-to-ms 1))
  (show-closest-snapshot!))

(defn click-later []
