(function() {
  var Thumbnail, ThumbnailViewer;
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  ThumbnailViewer = (function() {
    function ThumbnailViewer(gallery) {
      var el, i, _i, _len, _ref;
      this.gallery = gallery;
      this.index = 0;
      $(this.gallery).bind('slides:show', this.onSlide.bind(this));
      this.strips = $('.set');
      this.thumbnails = [];
      i = 0;
      _ref = $('.thumbnail').toArray();
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        el = _ref[_i];
        this.thumbnails.push(new Thumbnail($(el), i++, this.gallery));
      }
      this.stripIndex = 0;
      this.stripCount = this.strips.length;
      this.viewport = $('.vp');
      $('.thumbnails .previous').click(__bind(function() {
        this.scroll(this.stripIndex - 1);
        return false;
      }, this));
      $('.thumbnails .previous').click(__bind(function() {
        this.scroll(this.stripIndex - 1);
        return false;
      }, this));
      $('.thumbnails .next').click(__bind(function() {
        this.scroll(this.stripIndex + 1);
        return false;
      }, this));
    }
    ThumbnailViewer.prototype.onSlide = function(slide) {
      var newStripIndex, thumbnail;
      thumbnail = this.thumbnails[this.gallery.index];
      thumbnail.select();
      newStripIndex = thumbnail.element.closest('.set').data('index');
      if (this.stripIndex !== newStripIndex) {
        return this.scroll(newStripIndex);
      }
    };
    ThumbnailViewer.prototype.scroll = function(stripIndex) {
      var scrollLeft;
      if (stripIndex < 0 || (stripIndex + 1) > this.stripCount) {
        return;
      }
      this.stripIndex = stripIndex;
      if (this.stripIndex === 0) {
        $('.thumbnails .previous').addClass('disabled');
      } else {
        $('.thumbnails .previous').removeClass('disabled');
      }
      if (this.stripIndex + 1 === this.stripCount) {
        $('.thumbnails .next').addClass('disabled');
      } else {
        $('.thumbnails .next').removeClass('disabled');
      }
      scrollLeft = this.stripIndex * this.viewport.width();
      return this.viewport.animate({
        'scrollLeft': scrollLeft
      }, {
        queue: false,
        duration: 500,
        easing: 'swing'
      });
    };
    return ThumbnailViewer;
  })();
  Thumbnail = (function() {
    function Thumbnail(element, index, gallery) {
      this.element = element;
      this.index = index;
      this.gallery = gallery;
      this.element.click(this.click.bind(this));
    }
    Thumbnail.prototype.click = function() {
      return this.gallery.showSlide(this.index);
    };
    Thumbnail.prototype.select = function() {
      $('.thumbnail').removeClass('selected');
      return this.element.addClass('selected');
    };
    return Thumbnail;
  })();
  window.ThumbnailViewer = ThumbnailViewer;
}).call(this);

