function TSSRadioStatus(c) {
  if (typeof(c) == 'undefined') { c = {}; }

  this.update = function() {
    jQuery.ajax({url: this.url + '?t=' + new Date().getTime(), dataType: 'jsonp', jsonpCallback: 'ssr_status', success: this.success, error: this.error, complete: this.complete});
    if (this.interval != false) this.setTimeout();
  }
  
  this.init_elements = function() {
    this.elements = {};
    for (var k in this.selectors) this.elements[k] = jQuery(this.selectors[k]);
  }
  
  this.setTimeout = function(s) {
    var secs = s || this.interval;
    this.timeout = setTimeout(function(t) { t.update(); }, secs * 1000, this);
  }
  
  this.clearTimeout = function() {
    clearTimeout(this.timeout);
  }
  
  this.callback = {
    success: function(d) {
    },
    error: function(d) {
    },
    complete: function(d) {
      for (a in this.fields) {
        if (this.elements[a].length != 0) this.elements[a].html(d[a]);
      }
    }
  };
  
  // Settings
  this.url = c.url || 'http://radio.sonicstadium.org/status.json';
  this.success = c.success || this.callback.success;
  this.error = c.error || this.callback.error;
  this.complete = c.complete || this.callback.complete;
  this.auto = (c.auto == false) || true;
  this.interval = c.interval || 60;
  // Defaults
  this.selectors = c.selectors || {container: '#ssr', mount: '#ssr .mount', show: '#ssr .show', description: '#ssr .description', track: '#ssr .track', listeners: '#ssr .listeners', max_listeners: '#ssr .max_listeners'};
  this.fields = c.fields || {mount: 'mount', show: 'show', description: 'description', listeners: 'listeners', max_listeners: 'max_listeners', track: 'track'};
  // Null values
  this.timeout = null;
  
  this.init_elements();
  if (this.auto) this.update();
}

if (typeof jQuery === "undefined") {
  window.alert('TSSRadioStatus requires the jQuery library:\nhttp://www.jquery.com');
}
