   constructor: (images, options = {}) ->
     throw "You don't have defaultOptions or templates variables" if not defaultOptions or not templates
 
-    @options  = $.extend defaultOptions, options
-    isHistory = false if not @options.history
-
+    @options = $.extend defaultOptions, options
+
+    ###
+     Подготовка шаблонов
+    ###
     template = templates['overlay']
     template = template.replace '{{spinner}}', templates['spinner']
     template = template.replace '{{thumbnails}}', if @options.thumbnails then templates['thumbnails'] else ''
 
     @overlay = $(template).appendTo 'body'
 
-    elements = ['container', 'spinner', 'leftside', 'rightside', 'header']
-    elements.push 'thumbnails' if @options.thumbnails
-
-    @[element] = @overlay.find '.choco-' + element for element in elements
-
-    @overlay.find('.choco-close').click (event) => @close()
-
-    @_prepareActionFor element for element in ['overlay', 'container', 'leftside', 'rightside']
-
-    if isHistory
-      $(window).bind 'popstate', (event) =>
-        cid = @getImageFromUri()
-        if cid > 0 and cid isnt @current
-          if @current is null then @show cid else @open cid, false
+    ###
+     Получаем необходимые контейнеры
+    ###
+    containers = ['container', 'spinner', 'leftside', 'rightside', 'header']
+    containers.push 'thumbnails' if @options.thumbnails
+
+    @[container] = @overlay.find '.choco-' + container for container in containers
+
+    ###
+     Добавляем события по-умолчанию для контейнеров
+    ###
+    @overlay.find('.choco-close').click => @close()
+
+    @_prepareActionFor container for container in ['overlay', 'container', 'leftside', 'rightside']
 
     $(window).bind 'keyup', (event) =>
       if @overlay.hasClass 'show'


      @container.css 'background-image', 'url(' + image.source + ')'
      @header.html if image.title then templates['image-title'].replace '{{title}}', image.title else ''
    @

  ###
   Обновление миниатюр
  ###
  updateThumbnails: ->
    @thumbnails.find('.selected').removeClass 'selected'

    thumbnail = @thumbnails.find('[data-cid=' + @current + ']').addClass 'selected'

    width = thumbnail.outerWidth() + toInt thumbnail.css('margin-right')
    left  = thumbnail.offset().left

    if @thumbnails.width() < width + left
      offset = @thumbnails.scrollLeft() + width
      offset = width + left if @thumbnails.width() + offset < width + left

    else if @thumbnails.scrollLeft() > left
      offset = if left < width then 0 else @thumbnails.scrollLeft() - width

    @thumbnails.scrollLeft offset if offset > 0
    @

  ###


    @leftside.css  style
    @rightside.css style

    if title
      @header.addClass('show').css
        'width':       width
        'margin-left': '-' + left + 'px'
        'margin-top':  '-' + toInt(top + headerHeight) + 'px'

    style =
      'width':       width
      'height':      height
      'margin-left': '-' + left + 'px'
      'margin-top':  '-' + toInt(top) + 'px'

    @container.css style
    @spinner.css   style
