
  function Model(id) {
    this.id = id;
    this.host = "http://production.rapouts.com/";
    this.params = {};
    this.params[gadgets.io.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
    this.params[gadgets.io.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
    this.type = "model";
    
    // PRIVILEGED METHODS 
    this.render_response = function(data, url, error) {
      if (data == null) {
        alert("The request returned no data.");
      }
      else if (error)
      {
        alert("An error occured.")
      }
      // if there is data for the object we requested
      else
      {
        if (data.text) {
            data = data.text;
        }
        data = JSON.parse(data);
        if (data[this.type])
        {
          // check that there is the correct data type
          model = data[this.type]
          // check that we have the correct record
          if (model.id == this.id) 
          {
            for (property in model) 
            {
               // check if we recognize this property
               if (property in this)  {
                  this[property] = model.property;
                  this.render_property(property, model[property]);
               }
            }
          }
          else {
            alert("The specified model was not found.");
          }
        }
        else {
          alert("The specified data type was not found.");
        }
      }
    }    
    
    this.render_property = function(name, value) {
      element = document.getElementById(this.type + '_' + name);
      if (element) { element.innerHTML = value; }
    }
    
  }
  
  Campaign.prototype = new Model;
  function Campaign(id) {
    Model.call(this, id);
    this.type = "campaign";
    this.total_members = 0;
    this.total_video_views = 0;
    this.total_petition_signatures = 0;
    
        
    this.render = function(div) {
      gadgets.io.makeRequest(this.host + "campaigns/show/" + this.id, render_campaign, this.params);
    }
  }
  
  function render_campaign(data,url,error) {
    campaign.render_response(data,url,error)
  }
