 
     if isOpen
       slide = getTarget opened.slider, ".#{choco}slide"
-      return unless slide
+      return env unless slide
 
       needResize = false
 

      for container in ['overlay', 'leftside', 'rightside']
        prepareActionFor @, container

    @add images if images

    instances.push @




  close: ->
    isOpen = false
    opened = null
    if hasClass @overlay, choco_show
      removeClass @overlay, choco_show
      removeClass document.body, choco_body
      removeClass @current.thumbnail, choco_selected if @options.thumbnails
      @current = null
      pushState()
    @




  open: (cid, updateHistory) ->
    return if isOpen
    opened = @
    isOpen = true
    addClass @overlay, choco_show
    addClass document.body, choco_body
    @updateDimensions()
    @select cid, updateHistory
    @




  select: (item, updateHistory = true) ->

    if typeof item is 'number'
      item = @storage.get item

    return false unless item

    getEnv()

    translate @slider, env.shift * item.cid

    if @options.thumbnails

      removeClass @current.thumbnail, choco_selected if @current?

      thumb = item.thumbnail
      addClass thumb, choco_selected

      offset = env.w / 2 - thumb.offsetLeft - offsetWidth(thumb) / 2

      offset = squeeze offset, 0, env.w - @dimensions.thumbWidth
      translate @thumbnails, offset

    if updateHistory
      title = if item.title then item.title else item.hashbang
      pushState title, item.hashbang

    loading = hasClass item.slide, choco_loading
    if loading
      loadImage item, (success) =>
        @updateSides item
    else
      @updateSides item

    @current = item

    true




  next: ->
    @select @storage.next @current

        when 39 # Right arrow
          opened.next()

window.chocolate = Chocolate
