 
       if icon.width() > 0 or (icon[0].complete and icon[0].width > 0)
         # Image is already loaded (i.e. from cache)
-        @_onloadItem(itemIndex, obj) 
+        @_onloadItem itemIndex, obj
       else 
         # Create copy of the image and wait for the copy to load to get the real dimensions
         copy = $("<img style=\"display:none\"/>")

      Rondell.activeRondell is @id
    
    keyDown: (e) =>
      # Ignore event if some time has passed since last keyevent
      now = (new Date()).getTime()
      return if @_lastKeyEvent > now - @keyDelay

      if @isActive() and @isFocused()
        # Clear current rotation timer on user interaction
        if @autoRotation._timer >= 0
          window.clearTimeout(@autoRotation._timer) 
          @autoRotation._timer = -1

        @_lastKeyEvent = now
          
        switch e.which
          # arrow left
          when 37 then @shiftLeft(e)
          # arrow right 
          when 39 then @shiftRight(e) 


  class RondellScrollbar
    
    constructor: (container, options) ->
      @id = Wonderbar.wonderbarCount++
      @container = container.addClass "rondell-scrollbar"
      
      $.extend true, @, $.rondell.defaults.scrollbar, options
        
      @_initControls()
        
    _initControls: =>
      @scrollLeftControl = $("<div class=\"wonderbar-scroll-left\"/>")
        .bind "click", @scrollLeft
        
      @scrollRightControl = $("<div class=\"wonderbar-scroll-right\"/>")
        .bind "click", @scrollRight
        
      @scrollControl = $("<div class=\"wonderbar-scroll-control\"/>").css
        left: @container.innerWidth() / 2
        
      @scrollBackground = $("<div class=\"wonderbar-background\"/>")
        
      @container.bind "mousedown mouseup click", @doControl
      window.bind "mousemove", @doWindowControl
        
      @container.append @scrollBackground, @scrollLeftControl, @scrollRightControl, @scrollControl
      
    updatePosition: (position) =>
      return if position < @start or position > @end or position is @position
      
      @position = position
      
      # Fire callback with new position
      @onScroll?(position)
      
    scrollTo: (x, duration=@animationDuration) =>
      innerWidth = @container.innerWidth()
      return if x <= 0 or x >= innerWidth
      
      @scrollControl.stop(true).animate(
        left: x
      , duration, @easing)
      
      # Translate event coordinates to new position between start and end option
      newPosition = Math.round(x / innerWidth * (@end - @start) + @start)
      @updatePosition(newPosition) if newPosition isnt @position
      
    setPosition: (position) =>
      return if position < @start or position > @end or position is @position
      
      @position = position 
      
      # Translate position to new position for control dot in container
      @scrollTo(Math.round((position - @start) / (@end - @start) * @container.innerWidth()))

    doWindowControl: (e) =>
      switch e.type
        when "mousemove"
          return unless @drag.dragging
          @scrollTo(e.offsetX, 0) if e.target is @container[0]
      
    doControl: (e) =>
      e.preventDefault()
      
      switch e.type
        when "mousedown" then @drag.dragging = e.target is @scrollControl[0]
        when "mouseup" then @drag.dragging = false
        when "click" then @scrollTo(e.offsetX) if e.target is @container[0]
      
    scrollLeft: (e) =>
      e.preventDefault()
      @setPosition(@position - @stepSize)
      
    scrollRight: (e) => 
      e.preventDefault() 
      @setPosition(@position + @stepSize)
  
  $.fn.rondell = (options={}, callback=undefined) ->
    # Create new rondell instance
    rondell = new Rondell(options, @length, callback)
    
    # Wrap elements in new container
    rondell.container = @wrapAll($("<div class=\"rondellContainer initializing rondellTheme_#{rondell.theme}\"/>").css(rondell.size)).parent()
      
    # Show items hidden parent container to prevent graphical glitch
    rondell.container.parent().show() if rondell.showContainer
     
    # Setup each item
    @each (idx) ->

      @size = 
        width: @size.width or @center.left * 2
        height: @size.height or @center.top * 2

      # Wrap elements in new container
      @container = container.wrapAll($("<div class=\"rondellContainer initializing rondellTheme_#{@theme}\"/>").css(@size)).parent()
      
      # Show items hidden parent container to prevent graphical glitch
      @container.parent().show() if @showContainer

      # Create scrollbar
      if @scrollbar.enabled
        scrollbarContainer = $ "<div/>"
        @container.append scrollbarContainer

        $.extend true, @scrollbar,
          onScroll: @shiftTo
          start: 1
          end: @maxItems
          position: @currentLayer
          repeating: @repeating

        @scrollbar._instance = new RondellScrollbar(scrollbarContainer, @scrollbar)
    
    # Animation functions, can be different for each rondell
    funcLeft: (layerDiff, rondell, idx) ->
