document.write('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1jquery.min.js" >jQuery.noConflict();</script>');

function shortbordImgError(source, img){
  source.src = img;
  source.onerror = "";
  return true;
}

function sb_CreateEndorsement(surfer_id, div_id) {
  return ({
    partner:8,
    surfer:surfer_id,
    update_div_id:div_id,
    finalize:function() {
      var params = new Array();
      var i = 0;
      for (property in this) {
        if (this[property] instanceof Function) {
          // do nothing
        } else {
          params[i] = property + '=' + this[property];
          i++;
        }
      }
      jQuery.ajax({
         type: "GET",
         url: "http://www.shortbord.com/users/"+ this.surfer + "/endorsement?format=json&callback=?",
         data: params.join('&'),
         dataType: "json", 
         success: function(data){
           if (data.logo_url) {
             var html = '';
             if (data.shortbord_url) {
               html += "<a href='" + data.shortbord_url + "'>";
             }
             html += "<img alt='' src='" + data.logo_url + "' border='0' id='shortbord_icon_" + data.surfer_id + "' onerror='shortbordImgError(this, \"" + data.missing_logo_url +"\");'/>";
             //alert(html);
             if (data.shortbord_url) {
               html += "</a>";
             }
             jQuery('#' + data.update_div_id).html(html);
           }
         }
       });
    }
  })
}

var Shortbord = {
  getEndorsement:function(surfer, div_id) {
    if (div_id == null || div_id == '') {
      var div_id = ('shortbord_endorsement_' + Math.random()).replace('.', '');
      document.write("<div id='" + div_id + "'></div>");
    }
    return sb_CreateEndorsement(surfer, div_id);
  }
};
