   you at the 150 request/hour rate limit. We can speed it up for the demo."
   []
   (let [timer (goog.Timer. 24000)]
-    (do (listener)
+    (do (do-timer)
         (. timer (start))
-        (events/listen timer goog.Timer/TICK listener))))
+        (events/listen timer goog.Timer/TICK do-timer))))
 
+(defn do-track-button-clicked []
+  (send-event :track-clicked))
+
+(defn do-refresh-button-clicked []
+  (send-event :refresh-clicked))
+
+(defn start-app []
+  (events/listen (dom/getElement "twitter-search-button")
+                 "click"
+                 do-track-button-clicked)
+  (events/listen (dom/getElement "refresh-button")
+                 "click"
+                 do-refresh-button-clicked))
+
+;; this should be rolled up into one and the polling should only start
+;; when the track button is clicked.
+(start-app)
 (poll)
 
 (comment

        tweets (filter #(> (:id %) old-max)
                       (:results result-map))]
    (do  (swap! state update-state new-max tweets)
         (send-tweets (:new-tweets-listeners @state) tweets)
         (send-tweets (:graph-update-listeners @state) (:graph @state)))))

(defn register
  "Register a function to be called when new data arrives specifying
  the event to receive updates for. Events can be :new-tweets or :graph-update."
  [event f]
  (cond (= event :new-tweets) (add-listener :new-tweets-listeners f)
        (= event :graph-update) (add-listener :graph-update-listeners f)))

(defn search-tag
  "Get the current tag value from the page."
  []
  (.value (dom/getElement "twitter-search-tag")))

(defn listener []
  (retrieve (.strobj {"q" (search-tag)}) my-callback))

(defn poll


(def state (atom {:max-id 1
                  :graph {}
                  :listeners {:new-tweets []
                              :graph-update []
                              :track-clicked []
                              :refresh-clicked []}
                  :tweet-count 0}))

(defn add-listener [old-state k f]
  (let [l (-> old-state :listeners k)]
    (assoc-in old-state [:listeners k] (conj l f))))

(defn register
  "Register a function to be called when new data arrives specifying
  the event to receive updates for. Events can be :new-tweets or :graph-update."
  [event f]
  (swap! state add-listener event f))

(def twitter-uri (goog.Uri. "http://twitter.com/search.json"))

