var yp = new Array();
var idx = 0;

function latestnews (nws_id, div_name) {

    var callback_obj = "yp[" + idx + "]";

    var url = "http://pipes.yahoo.com/pipes/pipe.run?" 
	+ "&_id=20c41042cada1c1cef99f4cc48031e51" 
	+ "&_run=1" 
	+ "&_render=json";
  
    yp[idx] = new YPipesNews (url, div_name, callback_obj);
    yp[idx].requestJSON ();
    idx++;
}

// The YPipesNews constructor

function YPipesNews (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.

YPipesNews.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!.

YPipesNews.prototype.jsonHandler = function (json) {
  var div = document.getElementById (this.div_name);
  var news = json.value.items;
  var html = "";
  html += "<a href=" + news[0].link + ">" + news[0].title + "</a><br>\n";
  html += "<a href=" + news[1].link + ">" + news[1].title + "</a><br>\n";
  html += "<a href=" + news[2].link + ">" + news[2].title + "</a><br>\n";
  html += "<a href=" + news[3].link + ">" + news[3].title + "</a><br>\n";
  html += "<a href=" + news[4].link + ">" + news[4].title + "</a><br>\n";
  html += "<a href=" + news[5].link + ">" + news[5].title + "</a><br>\n";
  div.innerHTML = html;
}


