 ;; Atoms
 ;;------------------------------------------------------------------------------
 
-(def snapshots (atom nil))
+(def snapshot-list (atom nil))
+(def snapshot-index (atom nil)) ; can this be derived from current time, quickly?
 (def selected-time (atom nil))
-(def url-update-timout (atom nil)) ; This probably doesn't need to be atom, maybe be clojure feature that handles this
+(def url-update-timeout (atom nil)) ; This probably doesn't need to be atom, maybe be clojure feature that handles this
 
 ;;------------------------------------------------------------------------------
 ;; Timepicker

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

(defn use-index-time! [index]
  (swap! selected-time #(-> (@snapshot-list index) :time Date.)))

;;------------------------------------------------------------------------------
;; Watchers
;;------------------------------------------------------------------------------

(defn )

; TODO: Find closest index
(defn on-selected-time-change [_ _ _ new-time]
  (let [hour (.getHours new-time)
        meridian (if (> 11 hour) "PM" "AM")

(defn click-toggle-meridian []
  (let [hours (+ (get-hours) 12)
        hours (if (>= 24 ) (- 24 hours) hours)]
    (set-hours! hours)
    (show-closest-snapshot!)))

(defn click-decrement-hour []
  (set-hours! (dec (get-hours)))
  (show-closest-snapshot!))

(defn click-increment-hour []
  (set-hours! (inc (get-hours)))
  (show-closest-snapshot!))

(defn click-decrement-Minute []
  (set-minutes! (dec (get-minutes)))
  (show-closest-snapshot!))

(defn click-increment-minute []
  (set-minutes! (inc (get-minutes)))
  (show-closest-snapshot!)))

(defn click-later []
  (if (pos? @snapshot-index)
    (do
      (swap! snapshot-index dec)
      (sync-time-with-snapshot!))))

(defn click-earlier []
  (if (>= @snapshot-index (count @snapshot-list))
    (do
      (swap! snapshot-index inc)
      (sync-time-with-snapshot!))))

(defn add-events []
  (aset js/window "onpopstate" on-popstate)
