// Generated by CoffeeScript 1.6.2
(function() {
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  define(['marionette', 'vent', 'models/mix/mixCollection', 'views/mix/mixItemView', 'text!/tpl/MixListView'], function(Marionette, vent, MixCollection, MixItemView, Template) {
    var MixListView, _ref;

    MixListView = (function(_super) {
      var currentMix;

      __extends(MixListView, _super);

      function MixListView() {
        this.initialize = __bind(this.initialize, this);        _ref = MixListView.__super__.constructor.apply(this, arguments);
        return _ref;
      }

      MixListView.prototype.template = _.template(Template);

      MixListView.prototype.className = "mix-listing audio-listing";

      MixListView.prototype.itemView = MixItemView;

      MixListView.prototype.itemViewContainer = "#mix-list-container-ul";

      currentMix = -1;

      MixListView.prototype.initialize = function() {
        var _this = this;

        console.log("MixListView: initialize");
        this.collection = new MixCollection();
        this.collection.fetch({
          data: this.options,
          success: function() {
            console.log("MixListView: Collection fetched");
            _this.tabChanged(_this.options.order_by);
            _this.listenTo(vent, 'mix:play', _this.mixPlay);
            return true;
          }
        });
      };

      MixListView.prototype.mixPlay = function(model) {
        var v;

        console.log("MixListView: mixPlay");
        if (currentMix !== -1) {
          v = this.children.findByModelCid(currentMix);
          v.mixPause(v.model);
        }
        currentMix = model.cid;
      };

      MixListView.prototype.tabChanged = function(type) {
        console.log("MixListView: tab changed");
        $('#mix-tab li[id=li-' + type + ']', this.el).addClass('active');
        return true;
      };

      return MixListView;

    })(Marionette.CompositeView);
    return MixListView;
  });

}).call(this);
