/**
 * Get Weather Information
 *
 * @author: Rilwis
 * @url: http://hontap.blogspot.com
 * @email: rilwis@gmail.com
 * @license: MIT License
 */

/**
 * Callback function to show weather information
 */
function showWeatherCallback(data) {
	var channel = data.query.results.weather.rss.channel,
		img = channel.item.description.match(/http:\/\/[^"']*/),
		html = '<div style="color:#007741; font-weight:bold;height:32px; width:150px" id="weathers"><img style="vertical-align:bottom"  width="30" src="' + img + '" /> <div style="font-size:14px; position:absolute; top:5px; left:40px;color:#fff">' + channel.item.condition.temp + '&deg;C </div>' + 
				'<div class="cb"></div></div>';
	document.write(html);
}

/**
 * Show weather information. Use YQL to get information
 * location: in format "city, country"
 *
 * Ex: showWeather('hanoi,vietnam');
 */
function showWeather(location) {
	var baseUrl = 'http://query.yahooapis.com/v1/public/yql?q=',
		q = 'use "http://github.com/yql/yql-tables/raw/master/weather/weather.bylocation.xml" as we;' + 
			'select * from we where location="' + location + '" and unit="c"',
		url = baseUrl + encodeURIComponent(q) + '&format=json&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=showWeatherCallback';

	document.write('<script type="text/javascript" src="' + url + '"></' + 'script>');
}

