(function() {
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  window.PosterWallHandler = (function() {
    function PosterWallHandler(posterWall) {
      this.posterWall = posterWall;
      this.keyboardNavigationHandler = __bind(this.keyboardNavigationHandler, this);
      this.selectPosterAt = __bind(this.selectPosterAt, this);
      this.selectPoster = __bind(this.selectPoster, this);
      this.currentIndex = this.posterWall.data('index');
      this.posters = this.posterWall.find('li.poster');
      this.count = this.posters.length;
      this.width = $(this.posters.get(0)).width();
      this.kibo = new Kibo();
      this.kibo.down(['left', 'right'], this.keyboardNavigationHandler);
    }
    PosterWallHandler.prototype.selectPoster = function($event) {
      var $selectedPoster, index;
      $selectedPoster = $($event.data('poster'));
      index = this.posters.index($selectedPoster);
      return this.selectPosterAt(index);
    };
    PosterWallHandler.prototype.selectPosterAt = function(index) {
      var opts, props;
      this.posters.removeClass('selected');
      this.currentIndex = index;
      this.selectedPoster = $(this.posters.filter(":nth-child(" + (index + 1) + ")")[0]);
      this.selectedPoster.addClass('selected');
      props = {
        'marginLeft': -1 * this.currentIndex * this.width
      };
      opts = {
        duration: 500,
        queue: false
      };
      this.posters.filter('li:first-child').animate(props, opts);
      return this.selectedPoster;
    };
    PosterWallHandler.prototype.keyboardNavigationHandler = function(keys) {
      var newIndex, selectedPoster;
      if (keys.keyIdentifier === 'Left' && this.currentIndex !== 0) {
        newIndex = this.currentIndex - 1;
      } else if (keys.keyIdentifier === 'Right' && this.currentIndex !== (this.count - 1)) {
        newIndex = this.currentIndex + 1;
      } else {
        newIndex = this.currentIndex;
      }
      if (this.currentIndex !== newIndex) {
        selectedPoster = this.selectPosterAt(newIndex);
        selectedPoster.find('a').trigger('click');
      }
      return false;
    };
    return PosterWallHandler;
  })();
}).call(this);

