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

function photo_badge (div_name) {

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

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

// The YPipesWeather constructor

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

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

YPipesPhoto.prototype.jsonHandler = function (json) {
  var div = document.getElementById (this.div_name);

  var photo = json.value.items[0];

  var html = "";

   html += "<a href='http://www.uaf.edu/multimedia/gallery/" + photo.photo_URL + "'><img border='0' alt='Featured Photo' src='" 
	   + photo.photo_base
	   + photo.photo_name_sm
	   + "'></a><br><br>";

  html += "<span style='font-size: 8px;'>"
       + photo.photo_caption + "<br>"
	   + photo.photo_credit
	   + "</span><br><br>";

  html += "<span style='font-size: 9px;'><a href='"
       + photo.photo_gallery_URL + "'>"
	   + photo.photo_gallery + "</a>:&nbsp;<a href='"
	   + photo.photo_group_URL + "'>"
       + photo.photo_group + "</a></span><br>";

  html += "\n";

  div.innerHTML = html;

}


