       @g.zoomer.set "alignmentWidth", @maxWidth
     @el.style.width = Math.min calcWidth, @maxWidth
     @el.setAttribute 'width', @el.style.width
+
+  _getPrevNextSelection: (model) ->
+    # looks at the selection of the prev and next el
+    # TODO: this is very naive, as there might be gaps above or below
+
+    modelPrev = model.collection.prev model
+    modelNext = model.collection.next model
+    mPrevSel = @_getSelection modelPrev if modelPrev?
+    mNextSel = @_getSelection modelNext if modelNext?
+    [mPrevSel,mNextSel]
+
+

    for i in [0.. @model.length - 1] by 1
      continue if @model.at(i).get('hidden')
      @drawSeq {model: @model.at(i), y: y}
      #view = new SeqView {model: @model.at(i), g: @g}
      y = y + rectHeight

      # out of viewport - stop
      if y > @el.height
        break


    return selection

  appendFeature: (data) ->
    f = data.f
    # TODO: this is a very naive way of using SVG to display features
    boxWidth = @g.zoomer.get("columnWidth")
    boxHeight = @g.zoomer.get("rowHeight")
    width = (f.get("xEnd") - f.get("xStart")) * boxWidth

    beforeWidth = @ctx.lineWidth
    @ctx.lineWidth = 3
    beforeStyle = @ctx.strokeStyle
    @ctx.strokeStyle = f.get "fillColor"


    @ctx.strokeRect data.xZero, data.yZero, width,boxHeight
    @ctx.strokeStyle = beforeStyle
    @ctx.lineWidth = beforeWidth

  # displays the current user selection
  # and checks the prev and next row for selection  -> no borders in a selection
  _renderSelection: (data) ->

    xZero = data.xZero
    yZero = data.yZero
    n = data.n
    selection = data.selection
    mPrevSel= data.mPrevSel
    mNextSel = data.mNextSel

    # get the length of this selection
    selectionLength = 0
    for i in [n.. data.model.get("seq").length - 1] by 1

      if selection.indexOf(i) >= 0
        selectionLength++
      else
        break

    # TODO: ugly!
    boxWidth = @g.zoomer.get("columnWidth")
    boxHeight = @g.zoomer.get("rowHeight")
    totalWidth = (boxWidth * selectionLength) + 1

    hidden = @g.columns.get('hidden')

    @ctx.beginPath()
    beforeWidth = @ctx.lineWidth
    @ctx.lineWidth = 3
    beforeStyle = @ctx.strokeStyle
    @ctx.strokeStyle = "#FF0000"

    xZero += n * boxWidth

    # split up the selection into single cells
    xPart = 0
    for i in [0.. selectionLength - 1]
      xPos = n + i
      if hidden.indexOf(xPos) >= 0
        continue
      # upper line
      unless mPrevSel? and mPrevSel.indexOf(xPos) >= 0
        @ctx.moveTo xZero + xPart, yZero
        @ctx.lineTo xPart + boxWidth + xZero, yZero
      # lower line
      unless mNextSel? and mNextSel.indexOf(xPos) >= 0
        @ctx.moveTo xPart + xZero, boxHeight + yZero
        @ctx.lineTo xPart + boxWidth + xZero, boxHeight + yZero

      xPart += boxWidth

    # left
    @ctx.moveTo xZero,yZero
    @ctx.lineTo xZero, boxHeight + yZero

    # right
    @ctx.moveTo xZero + totalWidth,yZero
    @ctx.lineTo xZero + totalWidth, boxHeight + yZero

    @ctx.stroke()
    @ctx.strokeStyle = beforeStyle
    @ctx.lineWidth = beforeWidth

  _appendSelection: (data) ->
    seq = data.model.get("seq")
    selection = @_getSelection data.model
    hidden = @g.columns.get "hidden"
    # get the status of the upper and lower row
    [mPrevSel,mNextSel] = @_getPrevNextSelection data.model

    boxWidth = @g.zoomer.get("columnWidth")
    boxHeight = @g.zoomer.get("rowHeight")

    # avoid unnecessary loops
    return if selection.length is 0

    hiddenOffset = 0
    for n in [0..seq.length - 1] by 1
      if hidden.indexOf(n) >= 0
        hiddenOffset++
      else
        k = n - hiddenOffset
        # only if its a new selection
        if selection.indexOf(n) >= 0 and (k is 0 or selection.indexOf(n - 1) < 0 )
          @_renderSelection n:n,selection: selection,mPrevSel: mPrevSel,mNextSel:mNextSel, xZero: data.xZero, yZero: data.yZero, model: data.model



  _adjustWidth: ->
    if @el.parentNode?
