(function() {
  var MainView, stripTags,
    extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() 
 ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    hasProp = {}.hasOwnProperty;

  stripTags = function(input, allowed) {
    var commentsAndPhpTags, tags;
    allowed = (((allowed || '') + '').toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('');
    tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
    commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
    return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1) {
      if (allowed.indexOf('<' + $1.toLowerCase() + '>') > -1) {
        return $0;
      } else {
        return '';
      }
    });
  };

  KD.enableLogs;

  MainView = (function(superClass) {
    extend(MainView, superClass);

    function MainView() {
      MainView.__super__.constructor.apply(this, arguments);
      this.kite = KD.getSingleton("vmController");
      this.header = new KDHeaderView({
        type: "big",
        title: "KodioFM Holiday Radio"
      });
      this.talksWrapper = new KDCustomHTMLView({
        cssClass: "talks"
      });
      this.talk1 = new KDCustomHTMLView({
        cssClass: "talk1",
        partial: "<span>Why did the programmer quit his job?</span>"
      });
      this.talk2 = new KDCustomHTMLView({
        cssClass: "talk2",
        partial: "<span><h2>Ouch!</h2>Pines and needles!</span>"
      });
      this.talk3 = new KDCustomHTMLView({
        cssClass: "talk3",
        partial: "<span>Because he didn't get arrays.</span>"
      });
      this.talk4 = new KDCustomHTMLView({
        cssClass: "talk4",
        partial: "<span><h2>Sigh!</h2>Why do I still hangout with these guys?</span>"
      });
      this.talksWrapper.addSubView(this.talk1);
      this.talksWrapper.addSubView(this.talk2);
      this.talksWrapper.addSubView(this.talk3);
      this.talksWrapper.addSubView(this.talk4);
      this.characters = new KDCustomHTMLView({
        cssClass: "characters"
      });
      this.char1 = new KDCustomHTMLView({
        cssClass: "char1"
      });
      this.char2 = new KDCustomHTMLView({
        cssClass: "char2"
      });
      this.char3 = new KDCustomHTMLView({
        cssClass: "char3"
      });
      this.char4 = new KDCustomHTMLView({
        cssClass: "char4"
      });
      this.characters.addSubView(this.char2);
      this.characters.addSubView(this.char1);
      this.characters.addSubView(this.char3);
      this.characters.addSubView(this.char4);
      setTimeout((function(_this) {
        return function() {
          return $(".char2").hover(function() {
            $(".talk1").fadeIn(500);
            return $(".char1").hover(function() {
              $(".talk2").fadeIn(500);
              return $(".char3").hover(function() {
                $(".talk3").fadeIn(500);
                return $(".char4").hover(function() {
                  return $(".talk4").fadeIn(500);
                });
              });
            });
          });
        };
      })(this), 500);
      this.playerWrapper = new KDCustomHTMLView({
        cssClass: "playerWrapper"
      });
      this.playerWrapper.updatePartial('<audio id="audio-player" name="audio-player" src="http://108.61.73.118:8124/;">Your browser does not support the audio element.</audio>');
      this.playButton = new KDButtonView({
        cssClass: "playButton fa fa-play",
        tooltip: {
          title: "Play Radio!",
          placement: "bottom"
        },
        callback: (function(_this) {
          return function() {
            if (_this.playButton.hasClass("stopButton")) {
              _this.playButton.unsetClass("stopButton fa-stop");
              _this.playButton.setClass("playButton fa-play");
              _this.playerLabel.updatePartial("---");
              document.getElementById('audio-player').pause();
              return document.getElementById('audio-player').currentTime = 0;
            } else {
              setInterval(function() {
                return _this.getInfo("http://www.181.fm/station_playing/181-xtraditional.html");
              }, 10000);
              _this.playButton.unsetClass("playButton fa-play");
              _this.playButton.setClass("stopButton fa-stop");
              return document.getElementById('audio-player').play();
            }
          };
        })(this)
      });
      this.volumeMinus = new KDButtonView({
        cssClass: "volumeMinus fa fa-volume-down",
        tooltip: {
          title: "Volume Down!",
          placement: "bottom"
        },
        callback: (function(_this) {
          return function() {
            return document.getElementById('audio-player').volume -= 0.1;
          };
        })(this)
      });
      this.volumePlus = new KDButtonView({
        cssClass: "volumePlus fa fa-volume-up",
        tooltip: {
          title: "Volume Up!",
          placement: "bottom"
        },
        callback: (function(_this) {
          return function() {
            return document.getElementById('audio-player').volume += 0.1;
          };
        })(this)
      });
      this.playerWrapper.addSubView(this.playButton);
      this.playerWrapper.addSubView(this.volumeMinus);
      this.playerWrapper.addSubView(this.volumePlus);
      this.playerLabel = new KDCustomHTMLView({
        cssClass: "playerLabel",
        partial: "---"
      });
    }

    MainView.prototype.getInfo = function(url) {
      if (!url) {
        return;
      }
      return this.kite.run("curl -kLss " + url, (function(_this) {
        return function(error, data) {
          data = strip_tags(data);
          data = data.replace(/[\n\r\t]/g, "");
          data = data.substr(data.indexOf("CD") + 2);
          data = data.trim();
          return _this.playerLabel.updatePartial(data);
        };
      })(this));
    };

    MainView.prototype.pistachio = function() {
      return "<footer>\n    {{> @talksWrapper}}\n    {{> @characters}}\n    <section class=\"ground\">\n        {{> @header}}{{> @playerWrapper}}{{> @playerLabel}}\n    </section>\n</footer>";
    };

    appView.addSubView(new MainView({
      cssClass: "wrapper snowcontainer"
    }));

    return MainView;

  })(JView);

}).call(this);

{ this.constructor = child; }