var timer;

$(document).ready(function() {
	$.YQL("select * from weather.forecast where location=32905",function(data){
            var w=data.query.results.channel;
            $('#temp').html(w.item.condition.temp+"&deg;");
            var hi = w.item.forecast[0].high;
            var low = w.item.forecast[0].low;
            $('#hilo').html("Hi: " + hi + "<br> Low: " + low);
            var imgurl = "http://l.yimg.com/a/i/us/nws/weather/gr/"+w.item.condition.code+"d.png";
            $('#weather_icon').html('<img src="'+ imgurl +'">');
            $('#weather_loc').html('Current Conditions: <p id="city">' + w.location.city + ', ' + w.location.region + '</p>');
            
            timer = setInterval("updateWeather()", 300000);
       });
});

$.YQL = function(query, callback) {
    	var encodedQuery = encodeURIComponent(query.toLowerCase()),
       	 url = 'http://query.yahooapis.com/v1/public/yql?q='
            + encodedQuery + '&format=json&callback=?';
    	$.getJSON(url, callback);
};

function updateWeather() {
	$.YQL("select * from weather.forecast where location=32905",function(data){
            var w=data.query.results.channel;
            $('#temp').html(w.item.condition.temp+"&deg;");
            var hi = w.item.forecast[0].high;
            var low = w.item.forecast[0].low;
            $('#hilo').html("Hi: " + hi + "<br> Low: " + low);
            var imgurl = "http://l.yimg.com/a/i/us/nws/weather/gr/"+w.item.condition.code+"d.png";
            $('#weather_icon').html('<img src="'+ imgurl +'">');
             $('#weather_loc').html('Current Conditions: <p id="city">' + w.location.city + ', ' + w.location.region + '</p>');
       });
}

