 
 (def today (Date.))
 
-(defn start-day
+(defn first-day
   "First day to display on the calendar. Count back from the given date until
   the day is sunday (0)."
   [d]

(defn calendar-hiccup
  "Hiccup tempate for the calendar"
  [calendar-state]
  (let [d (:active-date calendar-state)
        events (:events calendar-state)]
    [:div.callie-view
     prev-next-today-btns 
     [:h2 {:class "month-year"} (month-year-span d)]
     [:table.table.table-bordered
      [:thead weekday-row]
      [:tbody (calendar-body d events)]]]))


(defn inject-cal! [calendar-state] 

   (for [x WEEKDAY-NAMES] 
     [:th x])])

(defn day-classes [d calendar-state]
  (cond-> []
    (is-today? d) (conj "today")
    (is-active-month? d calendar-state) (conj "active-month")
    (not (is-active-month? d)) (conj "not-active-month")))

(defn event-div [ev calendar-state]
  [:div {:class ["event"]}
   [:a [:span.time (.format event-time-formatter (:start ev))]
       [:span.title (:title ev)]]])

(defn day-cell [d calendar-state]
  (let [days-events (days-events-filter d (:events calendar-state))]
    [:td 
     {:class (string/join " " (day-classes d calendar-state))} 
     [:span {:class "daynumber"} (.getDate d)]
     (for [ev days-events]
       (event-div ev calendar-state))]))

(defn calendar-body 
  "6 weeks of days (The body of the calendar.)"
  [calendar-state]
  (let [start-day (first-day (:active-date calendar-state))
        all-days (take 6 (partition 7 (iterate next-day start-day)))]
    (for [week all-days]
      [:tr 
       (for [day week] (day-cell day calendar-state))])))

(def prev-next-today-btns 
  (list 
