var yp = new Array();
var idx = 0;

function twitter_badge (user_id, div_name) {

    var callback_obj = "yp[" + idx + "]";
// http://pipes.yahoo.com/pipes/pipe.run?_id=6983e3fc858975f79565664d72f79f7d&_render=json&username=stfyc
    var url = "http://pipes.yahoo.com/pipes/pipe.run?" 
	+ "&_id=6983e3fc858975f79565664d72f79f7d" 
	+ "&_render=json"
	+ "&username=" + user_id ;
  
    yp[idx] = new YPipesTwitter (url, div_name, callback_obj);
    yp[idx].requestJSON ();
    idx++;
}

// The YPipesTwitter constructor

function YPipesTwitter (ypipes_url, div_name, obj_name) {
  this.url = ypipes_url + "&_callback=" + obj_name + ".jsonHandler";
  this.div_name = div_name;
}

// The requestJSON method: it builds the script tag 
// that launches our request to the Yahoo! server.

YPipesTwitter.prototype.requestJSON = function () {

  // Dynamically create a script tag.  This initiates 
  // a request to the Yahoo! server.

  var head = document.getElementsByTagName("head").item(0);
  var script = document.createElement ("script");
  script.src = this.url;
  head.appendChild (script);
}

// The jsonHandler method: this is our callback function.
// It's called when the JSON is returned to our browser
// from Yahoo!.

YPipesTwitter.prototype.jsonHandler = function (json) {
  var div = document.getElementById (this.div_name);
  var cnt = parseInt(json.count);
  var twitter = json.value.items;

  var html = "";

  html += '<table cellspacing="0" cellpadding="0" border="0" class="tbadge" >';
  html += '<tr><td class="hdr"><h3>Latest StFYC 5O5 Tweets</h3></td></tr>';
  for (i = 0; i < cnt; i++) {
  html += '<tr><td class="desc"><a href="' + twitter[i].link + '" target=_blank>'  + twitter[i].description + "</a></td></tr>";
  html += '<tr><td class="pubtime">Published: ' + twitter[i].pubDate.substring(0 ,twitter[i].pubDate.indexOf("+")-1) + '</td></tr>';
}
  html += '</table>';


  div.innerHTML = html;

}



