         "endDate" end-date))))
 
 (defn init-timepicker []
-  )
+  (html ($ "timepickerContainer") (build-timepicker)))
 
 (defn init-snapshot-list []
   (swap! snapshot-list (fn []

    (prop ($ "#earlier") "disabled" (= (inc new-index) (count @snapshot-list)))
    (prop ($ "#later") "disabled" (zero? new-index))))

(add-watch snapshot-index :_ on-snapshot-index-change)

(defn on-selected-time-change [_ _ _ new-time]
  (let [hour (.getHours new-time)
        meridian (if (> 11 hour) "PM" "AM")
        hour (if (> 12 hour) (- hour 12) hour)]
    (val ($ "#hour") (pad hour))
    (val ($ "#minute") (pad (.getMinutes new-time)))
    (val ($ "#meridian") meridian)
    (.datepicker ($ "#datepicker") "update" new-time)))

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

;;------------------------------------------------------------------------------
;; Events
;;------------------------------------------------------------------------------

(defn on-popstate! [])

(defn on-datetime-change! []
  ); todo

(defn on-keydown! [e]
  (let [key (.-which e)]
    (cond
      (= key 37) (click-earlier!)
      (= key 39) (click-later!))))

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

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

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

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

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

(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!)
  (on ($ "datepicker") "changeDate" on-datetime-change!)
  (on ($ js/document) "keydown" on-keydown!)

  (-> ($ "body")
    (on "click" ".toggle-meridian" click-toggle-meridian!)
    (on "click" ".decrement-hour" click-decremen-hour!)
    (on "click" ".increment-hour" click-increment-hour!)
    (on "click" ".decrement-minute" click-decrement-Minute!)
    (on "click" ".increment-minute" click-increment-minute!)
    (on "click" "#later" click-later!)
    (on "click" "#earlier" click-earlier!)))

;;------------------------------------------------------------------------------
;; App Init

  (:require-macros [hiccups.core :as hiccups])
  (:require
    [hiccups.runtime :as hiccupsrt])
  (:use [jayq.core :only [$ document-ready html on attr prop text]]))

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

(def snapshots (atom nil))
(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

