(function() {
  var cs;
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  cs = window.CS || (window.CS = {});
  cs.Data || (cs.Data = {});
  cs.Views || (cs.Views = {});
  cs.Views.PeoplePromoView = Backbone.View.extend({
    renderCount: 0,
    personInt: 0,
    events: {
      'mouseover a.link': 'onMouse',
      'mouseout a.link': 'onMouse',
      'click a.link': 'onMouse'
    },
    initialize: function(options) {
      _.bindAll(this);
      this.appModel = options.appModel;
      this.$el = $(this.el);
      if (cs.Data.loaded) {
        this.render();
      } else {
        this.appModel.bind('site-preloader-animation-in-complete', this.render);
      }
    },
    render: function() {
      var people;
      if (this.int != null) {
        clearInterval(this.int);
      }
      if (this.renderCount === 0) {
        this.personInt = Math.floor(Math.random() * 15);
        this.person = cs.Data.people[this.personInt];
      }
      this.$el.html('');
      people = _.shuffle(cs.Data.people);
      this.$el.append("<div class=\"images\"></div>");
      _.each(people, __bind(function(person, index) {
        var url;
        if (index < 15) {
          if (index === this.personInt) {
            person = this.person;
          } else if (person === this.person) {
            person = people[16];
          }
          url = "" + cs.Data.templateDir + "/people/" + person.image;
          this.$('.images').append("<div class=\"image\"><img src=\"" + url + "\"/></div>");
        }
      }, this));
      this.$el.removeClass('loading');
      this.$el.append("<h4>Meet the crew</h4>");
      this.$el.append("<a href=\"" + cs.Data.index + "people\" class=\"link\"></a>");
      this.int = setTimeout(this.render, 2000);
      this.renderCount++;
      if (this.renderCount > 4) {
        this.renderCount = 0;
      }
    },
    onMouse: function(e) {
      clearInterval(this.int);
      switch (e.type) {
        case 'mouseover':
          if (this.mouseInt != null) {
            clearInterval(this.mouseInt);
          }
          this.mouseInt = setInterval(this.render, 360);
          break;
        case 'mouseout':
          clearInterval(this.mouseInt);
          this.render();
          break;
        case 'click':
          if (this.mouseInt != null) {
            clearInterval(this.mouseInt);
          }
      }
    }
  });
}).call(this);

