       @broken.push INF
       @nextBreak.push null
 
-     @breakCostMap = {}
-     @breakCostPositionMap = {}
      @breakCost = []
 
      for i in @mainNodes
-      @breakCost.push (@getBreakCost @map.nodes[i]) +
-                      (@getBreakTopCost @map.nodes[i])
+      @breakCost.push @getBreakCost @map.nodes[i]
 
      n = @mainNodes.length - 1
      while n >= 1

     p = Math.max p, 0.01
     #p = Math.sqrt p
     p = Math.min 1, p
     return parseInt EMPTY_PAGE_COST * (1 / p - 1)

    _parentPositionCost: (pos) ->
     p = pos / @pageHeight
     p = Math.max p, 0.01
     p = Math.sqrt p
     p = Math.min 1, p
     return parseInt PARENT_POSITION_COST * (1 / p - 1)


    getNodeBreakCost: (node) ->
     if BREAK_COST[node.type]?
      return BREAK_COST[node.type]
     else if node.type is 'section'
      return SECTION_BREAK_COST[node.leve]
     else
      throw new Error 'Unknown type'

    getBreakTopCost: (node) -> - @getNodeBreakCost node

    getBreakCost: (node) ->
     if @breakCostMap[node.id]?
      return @breakCostMap[node.id]

     parent = node.parent()

     if parent?
      @breakCostMap[node.id] = @breakCostMap[parent.id]
      while parent?
       pos = (@getOffsetTop node.elem, @elems.main) -
             (@getOffsetTop parent.elem, @elems.main)
       @breakCostMap[node.id] += @_parentPositionCost pos
       parent = parent.parent()
     else
      if node.type isnt 'article'
       throw new Error 'oops'
      @breakCostMap[node.id] = 0

     @breakCostMap[node.id] += @getNodeBreakCost node

     return @breakCostMap[node.id]


    getOffsetTop: (elem, parent) ->
     top = 0

    6: 155


   PARENT_POSITION_COST = 500
   EMPTY_PAGE_COST = 200

   PAGE_MARGIN = '1000px'
   START = 1
