(function() {
  var cs;

  cs = window.CS || (window.CS = {});

  cs.Data || (cs.Data = {});

  cs.Views || (cs.Views = {});

  cs.Views.BigLocationsPromoView = Backbone.View.extend({
    initialize: function(options) {
      this.options = options;
      _.bindAll(this);
      this.$el = $(this.el);
      if (cs.Data.loaded) {
        this.render();
      } else {
        this.options.appModel.bind('site-preloader-animation-in-complete', this.render);
      }
    },
    render: function() {
      var _this = this;
      this.$el.append("<table cellpadding=\"0\" cellspacing=\"0\" class=\"spots\"><tr></tr></table>");
      _.each(cs.Data.locations, function(location) {
        var $spot;
        $spot = $("<td class=\"spot\">        <a href=\"" + location.url + "\" class=\"link\"></a>        <img src=\"" + cs.Data.templateDir + "/locations/" + location.image + "\" />        <h4 class=\"name\">" + location.name + "</h4>      </td>        ");
        _this.$('.spots tr').append($spot);
      });
      _.each(this.$('td.spot'), function(el) {
        var $clone, $el;
        $el = $(el);
        $clone = $el.clone();
        _this.$('.spots tr').append($clone);
      });
      this.$('table.spots').css({
        width: (this.$('td.spot').length * 320) + 25
      });
      this.$el.bind('mouseover', this.mouseAction);
      this.$el.bind('mouseout', this.mouseAction);
      this.$el.bind('scroll', this.onScroll);
      this.scrollInt = setInterval(this.scroll, 24);
      setTimeout(this.positionText);
      _.each(this.$('td.spot'), function(el, index) {
        var $el, $h4;
        $el = $(el);
        if (index % 2 === 0) $el.addClass('even');
        $h4 = $el.find('h4');
        $h4.css({
          marginTop: 0 - ($el.find('h4').height() / 2)
        });
      });
    },
    scroll: function(e) {
      var newX, x;
      x = this.$el.scrollLeft();
      newX = x + 1;
      this.$el.scrollLeft(newX);
    },
    onScroll: function(e) {
      var x;
      x = this.$el.scrollLeft();
      if (x > (cs.Data.locations.length * 320)) this.$el.scrollLeft(0);
    },
    mouseAction: function(e) {
      switch (e.type) {
        case 'mouseover':
          clearInterval(this.scrollInt);
          break;
        case 'mouseout':
          this.scrollInt = setInterval(this.scroll, 24);
      }
    }
  });

}).call(this);

