     itemOptions.childOptions or= itemChildOptions
 
     itemInstance = new (@getOptions().itemClass ? KDListItemView) itemOptions, itemData
-    @addItemView itemInstance, index, animation
+    @addItemView itemInstance, index
 
     return itemInstance
 
-  removeItem:(itemInstance, itemData, index)->
+
+  removeItem: (itemInstance, itemData, index) ->
 
     if index?
       @emit 'ItemIsBeingDestroyed', { view : @items[index], index : index }


module.exports = class KDListView extends KDView

  constructor:(options = {}, data)->

    options.type       or= "default"
    options.lastToFirst ?= no
    options.cssClass     = if options.cssClass? then "kdlistview kdlistview-#{options.type} #{options.cssClass}" else "kdlistview kdlistview-#{options.type}"

    @items = [] unless @items

    super options,data

  empty:->

    for item,i in @items
      item.destroy() if item?
    @items = []

  keyDown:(event)->

    event.stopPropagation()
    event.preventDefault()
    @emit "KeyDownOnList", event

  addItem:(itemData, index, animation)->

    {itemChildClass, itemChildOptions} = @getOptions()

    if index? and typeof index isnt 'number'
      itemOptions = index
      index = null
    else
      {itemOptions} = @getOptions()


          item.destroy()
          return


  removeItemByData: (itemData) -> @removeItem null, itemData


  removeItemByIndex: (index) -> @removeItem null, null, index


  destroy: ->

    item.destroy() for item in @items

    super


  addItemView: (itemInstance, index = 0) ->

    {lastToFirst} = @getOptions()

    @emit 'ItemWasAdded', itemInstance, index

    if index?
      actualIndex = if lastToFirst then @items.length - index - 1 else index
      @items.splice actualIndex, 0, itemInstance
    else
      if lastToFirst
      then @items.unshift itemInstance
      else @items.push itemInstance

    @appendItemAtIndex itemInstance, index

    return itemInstance


  appendItem: (itemInstance) -> @appendItemAtIndex itemInstance


  appendItemAtIndex: (itemInstance, index = 0) ->

    itemInstance.setParent @

    scroll        = @doIHaveToScroll()
    {lastToFirst} = @getOptions()
    $item         = itemInstance.$()

    if index is 0

      if lastToFirst
      then @$().prepend $item
      else @$().append $item

    else if index > 0

      if lastToFirst
        index = @items.length - index - 2
        @items[index].$().before $item
      else
        index -= 1
        @items[index].$().after  $item

    @scrollDown() if scroll

    itemInstance.emit 'viewAppended'  if @parentIsInDom

    null


  getItemIndex:(targetItem)->
    for item, index in @items
      return index if item is targetItem
    return -1


  moveItemToIndex:(item, newIndex)->

