 
 
 (defn items-view [data owner]
-  (apply dom/div nil 
-         (om/build-all item-view 
-                       (filter
-                         #(or (= (:type %) "photo") (= (:type %) "audio"))
-                         (:current-items data))
-                       {:state {:visible (:search-options data)}}
-                       )))
+  (let [col-n (quot (:window-width data) IMGSIZE)
+        left-offset (/ (mod (.. js/window -innerWidth) IMGSIZE) 2)]
+    (apply dom/div #js {:className "images"}
+           (om/build-all 
+             item-view 
+             (->> (:current-items data)
+                  (filter #(= (:type %) "photo"))
+                  ((fn [items]
+                    (loop [is items coll [] idx 0 offsets (vec (repeat col-n 0))]
+                      (if (empty? is) coll
+                        (let [item  (first is)
+                              title (s/replace (:slug item)  #"-"  " ") 
+                              photo (-> item :photos first :alt_sizes second)]
+                          (if (or (nil? (:height photo)) (nil? (:width photo)))
+                            ; nil size found
+                            (recur (rest is) coll idx offsets)
+                            ; ok
+                            (let [offset-n    (mod idx col-n)
+                                  offset-x    (+ left-offset (* IMGSIZE offset-n))
+                                  offset-y    (offsets offset-n)
+                                  new-height  (.round js/Math (* (:height photo) (/ IMGSIZE (:width photo))))
+                                  new-offsets (update-in offsets [offset-n] #(+ % new-height))
+                                  new-item {:index idx
+                                            :title title
+                                            :photo photo
+                                            :x offset-x
+                                            :y offset-y}]
+                              (recur
+                                (rest is)
+                                (conj coll new-item)
+                                (inc idx)
+                                new-offsets)))
+                          ))))))))))
 
 (defn item-view [item owner]
-  (if
-    (= (:type item) "photo")
-    (reify
-      om/IRender
-      (render [_]
-        (dom/div #js {:data-type (:type item)
-                      :className (if (-> owner om/get-state :visible :photo)
-                                   "shown"
-                                   "hidden")}
-                 (dom/h2 nil (s/replace (:slug item)  #"-"  " "))
-                 (dom/a #js {:href (:post_url item) :target "_blank"}
-                        (dom/img #js {:src (-> item :photos first :alt_sizes second :url)})))))
-    (reify
-      om/IRender
-      (render [_]
-        (dom/div #js {:data-type true
-                      :className (if (-> owner om/get-state :visible :audio) 
-                                   "shown"
-                                   "hidden")}
-                 (dom/h2 nil (s/replace (:slug item)  #"-"  " "))
-                 (dom/div 
-                   #js {:dangerouslySetInnerHTML #js {:__html (:player item)}}
-                   nil)))) 
-    ))
+  (reify
+    om/IRender
+    (render [_]
+      (dom/a #js {:href (:post_url item) :target "_blank"
+                  :style #js {:position "absolute"
+                              :height (str (:height (:photo item)) "px")
+                              :width (str IMGSIZE "px")
+                              :top (str (:y item) "px")
+                              :left (str (:x item) "px")
+                              }}
+             (dom/img #js {:src (:url (:photo item))})))))
 
 
 ;; Loading ------------------------------------------------

        (om/transact! data #(assoc % :current-state :loading))
        (go (async-search @data ajax-chan))))))


(om/root
  (fn [data owner]

(defn render-loaded [data owner]
  (om/component
    (dom/div nil
             (dom/div #js {:className "header"}
                      ; title
                      (dom/h1 nil (str "Current search: " 
                                       (:current-search data)))

                      (dom/button
                        #js {:onClick (fn [e]
                                        (.preventDefault e)
                                        (om/transact! data reset-state))}
                        "Reset"))
             ; item list
             (items-view data owner)
             )))
