$(document).ready(function() {

/* Yahoo Weather Feed */
	$.YQL = function(query, callback) {
		if (!query || !callback) {
			throw new Error('$.YQL(): Parameters may be undefined');
		}
		var encodedQuery = encodeURIComponent(query.toLowerCase()),
			url = 'http://query.yahooapis.com/v1/public/yql?q='
				+ encodedQuery + '&format=json&callback=?';
		$.getJSON(url, callback);
	};

	$.YQL("select * from weather.forecast where location=32202",function(data){
		var w=data.query.results.channel;
		var weatherImage="url(http://l.yimg.com/a/i/us/nws/weather/gr/"+w.item.condition.code+"d.png)";
		var wd=w.wind.direction;
		if(wd>=348.75&&wd<=360){wd="N"};if(wd>=0&&wd<11.25){wd="N"};if(wd>=11.25&&wd<33.75){wd="NNE"};if(wd>=33.75&&wd<56.25){wd="NE"};if(wd>=56.25&&wd<78.75){wd="ENE"};if(wd>=78.75&&wd<101.25){wd="E"};if(wd>=101.25&&wd<123.75){wd="ESE"};if(wd>=123.75&&wd<146.25){wd="SE"};if(wd>=146.25&&wd<168.75){wd="SSE"};if(wd>=168.75&&wd<191.25){wd="S"};if(wd>=191.25 && wd<213.75){wd="SSW"};if(wd>=213.75&&wd<236.25){wd="SW"};if(wd>=236.25&&wd<258.75){wd="WSW"};if(wd>=258.75 && wd<281.25){wd="W"};if(wd>=281.25&&wd<303.75){wd="WNW"};if(wd>=303.75&&wd<326.25){wd="NW"};if(wd>=326.25&&wd<348.75){wd="NNW"};
		
		$('#weatherWidget').css("background-image",weatherImage);
		$('#weatherCity').html("<h2>"+w.location.city+"</h2>");
	    $('#weatherDescription').html("<h3>"+w.item.condition.text+"</h3><p><span>Feels Like:</span> "+w.item.condition.temp+" &deg;F<br/><span>Barometer:</span> "+w.atmosphere.pressure+" "+w.units.pressure+"<br/><span>Humidity:</span> "+w.atmosphere.humidity+" %<br/><span>Visibility:</span> "+w.atmosphere.visibility+" mi<br/><span>Wind:</span>"+wd+" "+w.wind.speed+" mph</p><p>"+w.item.condition.date+"</p>");
		$('#weatherConditions').html("<h5>"+w.item.condition.temp+"&deg;</h5><p>High: <strong>"+w.item.forecast[0].high+"&deg;</strong> Low: <strong>"+w.item.forecast[0].low+"&deg;</strong></p>");		
	});
	
});