 ;  [:tr [:td#.num 1] [:td#.num 2] [:td#.cell.c0.r1] [:td#.cell.c1.r1] [:td#.cell.c2.r1] [:td#.cell.c3.r1]]
 ;  [:tr [:td]        [:td#.num 2] [:td#.cell.c0.r2] [:td#.cell.c1.r2] [:td#.cell.c2.r2] [:td#.cell.c3.r2]]
 ;  [:tr [:td]        [:td#.num 4] [:td#.cell.c0.r3] [:td#.cell.c1.r3] [:td#.cell.c2.r3] [:td#.cell.c3.r3]]])
+
+(def state (atom {:clicking :none})) ;one of [:none :left :right]
 
 (def data {:left [[3 1] [3] [2] [1 1] [1 1]]
            :top [[1 1] [1 3] [2] [1 2] [2]]})

        cols-wrong (get wrong :cols-wrong)]
    (js/alert (str "rows" rows-wrong " cols" cols-wrong))))

(defn add-handlers []
  (let [cells (sel ".cell")
        nums (sel ".num")]
      (doseq [cell cells]
        (set! (.-onmousedown cell) #(cell-click % cell))
        (set! (.-oncontextmenu cell) (fn [evt] false)))
      (doseq [num nums]
        (set! (.-onmousedown num) #(num-click % num))
        (set! (.-oncontextmenu num) (fn [evt] false)))
      (dommy/listen! (sel1 :#button-done) :click done-handler))
  (dommy/listen! (sel1 :#button-clear) :click clear-puzzle))

(defn clear-puzzle []
  (doseq [class ["num-clicked" "cell-clicked" "cell-rightclicked"]
          el (sel (str "." class))]
    (dommy/remove-class! el class)))

(defn show [nono]
  (do
    (dommy/replace! (sel1 :#puzzle-table) (create-template nono))

  "Change the color when cell is clicked"
  (case (.-which evt)
    1 (do (dommy/toggle-class! node "cell-clicked")
          (dommy/remove-class! node "cell-rightclicked")
          (swap! state assoc :clicking :left))
    3 (do (dommy/toggle-class! node "cell-rightclicked")
          (dommy/remove-class! node "cell-clicked")
          (swap! state assoc :clicking :right))
    nil))

(defn num-click [evt node]
