 
 
 
+
+class EventRegister
+
+    constructor: ->
+        @boundEvents = []
+
+    bind: (target, evt, cb)->
+        @boundEvents.push [target, evt, cb]
+        target.addEventListener evt, cb
+
+    unbindAll: ->
+        for [target, evt, cb] in @boundEvents
+            target.removeEventListener evt, cb
+        @boundEvents = []
+
+
 class ScrollBarProxy
 
-    constructor: (@container, @W, @H)->
+    constructor: (@container, @W, @H, eventRegister)->
         @verticalScrollbar = document.createElement "div"
         @verticalScrollbar.className += " fattable-v-scrollbar"
         @horizontalScrollbar = document.createElement "div"

            @painter.setupColumnHeader el
            @columns[c] = el
            @headerViewport.appendChild el
        @firstVisibleRow = @nbRowsVisible
        @firstVisibleColumn = @nbColsVisible
        @display 0,0

        @container.appendChild @headerContainer
        @bodyContainer.appendChild @bodyViewport
        @refreshAllContent()
        @scroll = new ScrollBarProxy @bodyContainer, @W, @H, @eventRegister
        @scroll.onScroll = (x,y)=>
            [i,j] = @visible x,y
            @display i,j
