function updateForecastWidget(station, num) {

  $.getJSON('http://web1.opb.org/weatherservices/forecastByStation/' + station + '?callback=?',
    function(data) {
		$.cookie('WEATHER_STATION', station, {expires: 14});
		$("#weatherVert_city").html(data.city + ", " + data.state);
			for (var i=0;i<num;i++) {
			
			
			if(num != 5) {
				var id = "#weatherVert" + i;
				$(id + " > div.weatherVert_day").html(data.periods[i*2].replace(" Night",""));
				$(id + " > div.weatherVert_icon > img").attr("src", "/media/images/weather/" + data.icons[i*2] + ".gif");
				$(id + " > div.weatherVert_temps > p.high").html(data.maxtemps[i] + "&#176;");
				$(id + " > div.weatherVert_temps > p.low").html(data.mintemps[i] + "&#176;");
				
			}
			
			if(num == 5) {
				var id = "#weatherHorz" + i;
				$(id + " > div.weatherHorz_day").html(data.periods[i*2].replace(" Night",""));
				$(id + " > div.weatherHorz_icon > img").attr("src", "/media/images/weather/" + data.icons[i*2] + ".gif");
				$(id + " > div.weatherHorz_temps > span.high").html(data.maxtemps[i] + "&#176;");
				$(id + " > div.weatherHorz_temps > span.low").html(data.mintemps[i] + "&#176;");
				$(id + " > div.weatherHorz_weather > p.weather").html(data.weather[i*2]);
			}
			
		}
		
		
    });
}

function initForecastWidget(num) {
  $.getJSON('http://web1.opb.org/weatherservices/listStations/?callback=?',
	function(data) {
		var station = $.cookie('WEATHER_STATION');
		if (station == null) station = 'KPDX';

		$("#forecastCity").html("");
		for (var i=0;i<data.length;i++) {
			if (station == data[i].station) {
				$("#forecastCity").append("<option selected value=\""+data[i].station+"\">"+data[i].name+", "+data[i].state+"</option>");
			} else {
				$("#forecastCity").append("<option value=\""+data[i].station+"\">"+data[i].name+", "+data[i].state+"</option>");
			}
		}
		updateForecastWidget(station, num);
	});
}

function forecastWidget(num) {
  var stationMenu = document.getElementById("forecastCity");
  var station = stationMenu.options[stationMenu.selectedIndex].value;
  updateForecastWidget(station, num);
}
