 distance = (a1, a2)->
     Math.abs(a2-a1)
 
+closest = (x, vals...)->
+    d = 99999
+    res = undefined
+    for x_ in vals
+        d_ = distance x,x_
+        if d_ < d
+            d = d_
+            res = x_
+    res
+
 class TableView
 
     constructor: (container, @data, @layout)->

        @last_j = j


layout =
    columnHeaderHeight: 100
    row_height:  20
    column_width: ( 50 for i in [0...100] )

table_data = new TableData (generate_table 1000,500)
window.table_view = new TableView "#container", table_data, layout














        @headerContainer = document.createElement "div"
        @headerContainer.style.position =  "absolute"
        @headerContainer.style.top = "0px";
        @headerContainer.style.height = @layout.header_height + "px";
        @headerContainer.style.width = "100%";
        @headerContainer.className = "header-container"
        
        @headerViewport =  document.createElement "div"
        @headerViewport.className = "viewport"
        @headerViewport.style.width = @W + "px"
        @headerViewport.style.height = @layout.header_height + "px"
        @headerViewport.style.overflow = "hidden"
        @headerContainer.appendChild @headerViewport

        # body container 
        @bodyContainer = document.createElement "div"
        @bodyContainer.style.position =  "absolute"
        @bodyContainer.style.top = @layout.header_height + "px";
        @bodyContainer.style.bottom = "0px";
        @bodyContainer.style.width = "100%";

