(function() {
  /*
  SCPRv4: Southern California Public Radio
  */  if (typeof scpr === "undefined" || scpr === null) {
    scpr = {};
  }
}).call(this);
(function() {
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  scpr.ActiveContent = (function() {
    ActiveContent.prototype.DefaultOptions = {
      tabs: [],
      dvalue: 1,
      cookie: null
    };
    function ActiveContent(options) {
      var init;
      this.options = _(_({}).extend(this.DefaultOptions)).extend(options || {});
      _(this.options.tabs).each(__bind(function(id, idx) {
        return $("#" + id + "_c").bind("click", __bind(function() {
          return this.clickedTab(id, idx);
        }, this));
      }, this));
      init = this.options.dvalue;
      if (this.options.cookie) {
        init = scpr.Cookie.get(this.options.cookie) || this.options.dvalue;
      }
      this.clickedTab(this.options.tabs[init - 1], init - 1);
    }
    ActiveContent.prototype.clickedTab = function(tab, idx) {
      var id, _i, _len, _ref;
      _ref = this.options.tabs;
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        id = _ref[_i];
        $("#" + id).hide();
        $("#" + id + "_c").removeClass("active");
      }
      $("#" + tab).show();
      $("#" + tab + "_c").addClass('active');
      if (this.options.cookie) {
        return scpr.Cookie.set(this.options.cookie, idx + 1, 86400);
      }
    };
    return ActiveContent;
  })();
  /*
   cookie code originally from prototype-tidbits
   http://livepipe.net/projects/prototype_tidbits/
  */
  scpr.Cookie = (function() {
    function Cookie() {}
    Cookie.set = function(name, value, seconds) {
      var d, expiry;
      if (seconds) {
        d = new Date();
        d.setTime(d.getTime() + (seconds * 1000));
        expiry = '; expires=' + d.toGMTString();
      } else {
        expiry = '';
      }
      return document.cookie = name + "=" + value + expiry + "; path=/";
    };
    Cookie.get = function(name) {
      var c, ca, nameEQ, _i, _len;
      nameEQ = name + "=";
      ca = document.cookie.split(';');
      for (_i = 0, _len = ca.length; _i < _len; _i++) {
        c = ca[_i];
        while (c.charAt(0) === ' ') {
          c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) === 0) {
          return c.substring(nameEQ.length, c.length);
        }
      }
      return null;
    };
    Cookie.unset = function(name) {
      return scpr.Cookie.set(name, '', -1);
    };
    return Cookie;
  })();
}).call(this);

