                          .replace('{{image}}', image.thumbnail)
                          .replace('{{title}}', if image.title then " title=\"#{image.title}\"" else '')
 
-    $(@thumbnails).html(content).find('.choco-thumbnail').each ->
-      thumbnail = $ @
-      image = @getAttribute 'data-image'
-
-      thumbnail.on 'click', -> _this.open toInt thumbnail.attr 'data-cid'
-      setStyle @, "background-image": "url(#{image})"
+    @thumbnails.innerHTML = content
+    [].forEach.call @thumbnails.querySelectorAll('.choco-thumbnail'), (thumbnail) ->
+      image = thumbnail.getAttribute 'data-image'
+
+      addHandler thumbnail, 'click', -> _this.open toInt @getAttribute 'data-cid'
+      setStyle thumbnail, "background-image": "url(#{image})"
 
     addHandler @overlay, 'click', ->
       current = _this.images[_this.current]

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

    before = $(@thumbnails).find('.selected').removeClass('selected').attr 'data-cid'
    after  = @thumbnails.querySelector "[data-cid='#{@current}']"
    addClass after, 'selected'

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

    width     = $(@thumbnails).width()
    element   = $(after).get(0).offsetLeft
    thumbnail = @dimensions.thumbnail
    container = $(@thumbnails).get(0).scrollLeft or 0

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


      if @options.thumbnails
        @thumbnails.innerHTML = ''
        removeHandler @overlay, 'click', '.choc-thumbnails-toggle'

      removeHandler window, 'resize'

      @current = null

