var AboutUsWidget = {
  currentId: ((typeof AboutUsWidget != 'undefined') ? AboutUsWidget.currentId : 0),
  getId: function() {
    return this.currentId += 1;
  },
  getDivId: function(i) {
    return "AboutUsWidget-" + i;
  },
  add: function(domain) {
    var host = "http://www.aboutus.org";
    var spinnerUrl = host + "/static/images/spinner_small.gif"
    var id = this.getId();
    document.write("<div id=\"" + this.getDivId(id) + "\"><img src=\"" + spinnerUrl +"\"></img></div>");

    var url = host + '/' + domain + '?format=widget_jsonp&div_id=' + id;

    this.addLoadEvent(function() {
      var script = document.createElement('script');
      script.src = url;
      document.body.appendChild(script);
    });
  },
  addLoadEvent: function(callback) {
    var oldOnload = window.onload;
    if(typeof window.onload != "function") {
      window.onload = callback;
    } else {
      window.onload = function() {
        oldOnload();
        callback();
      }
    }
  },
  addContent: function(content, id) {
    var div = document.getElementById(this.getDivId(id));
    div.innerHTML = content;
  }
};