           'margin-top': "#{-1 * image.offsetHeight}px"
 
         addHandler image, ['mouseenter', 'mouseleave'], ->
-          toggleClass popover[0], 'choco-hover'
-
-        addHandler popover[0], 'click', (event) ->
+          toggleClass popover, 'choco-hover'
+
+        addHandler popover, 'click', (event) ->
           showFirstImage event, cid
 
       preload.src = data.thumbnail

    for ev in event
      target.addEventListener ev, listener, false

hasClassList = (element, selector) ->
  target = getTarget element, selector
  if target? and target.hasOwnProperty 'classList'

  updateThumbnails: ->
    return @ if not @options.thumbnails or @length <= 1

    before = @thumbnails.querySelector '.selected'
    if before?
      removeClass before, 'selected'
      before = before.getAttribute 'data-cid'
    after  = @thumbnails.querySelector "[data-cid='#{@current}']"
    addClass after, 'selected'

    if not @dimensions.thumbnail
      @dimensions.thumbnail = toInt @_outerWidth after

    width     = @thumbnails.offsetWidth
    element   = after.offsetLeft
    thumbnail = @dimensions.thumbnail
    container = @thumbnails.scrollLeft or 0

    if before
      offset = if @current > before then container + thumbnail else container - thumbnail
