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

function weather_badge (nws_id, div_name) {

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

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

// The YPipesWeather constructor

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

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

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

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

  var html = "";


  html += "<table style='font-size: 12px;'><tr><td>" 

  html += "<a href='http://forecast.weather.gov/MapClick.php?zoneid=AKZ222' target='_blank'><img border='0' src='" 
       + weather.icon_url_base 
       + weather.icon_url_name 
  + "'></a></td><td>";

 html += weather.weather + "<br>";
 html += weather.temperature_string + "<br>";

  html +="</td></tr></table>";
  


  div.innerHTML = html;

}


