 document.addEventListener "DOMContentLoaded", =>
     document.removeEventListener "DOMContentLoaded", arguments.callee
 
+
+bound = (x, m, M)->
+    if (x < m) then m else if (x > M) then M else x
 
 class Promise
 

                        @painter.fillCellPending cell
        @firstVisibleRow = i

window.fattable = (params)->
    new TableView params

window.fattable.TableData = TableData
window.fattable.TableView = TableView
window.fattable.CellPainter = CellPainter
window.fattable.PagedAsyncTableData = PagedAsyncTableData
window.fattable.SyncTableData = SyncTableData
    onScrollXY: (x,y)->

    setScrollXY: (x,y)->
        x = bound(x, 0, @maxScrollHorizontal)
        y = bound(y, 0, @maxScrollVertical)
        @scrollLeft = x
        @scrollTop = y
        @horizontalScrollbar.scrollLeft = x
