/*

Shows weather forecast in element.
Requires gwproxy.php to be present on webserver
container is a jQuery element or selector
locale and location are strings.
location could be whatever google accepts like 
'New York' or ',,,22500000,31000000' to get weather for lat=22.5 and long=31

*/

function showWeather(container,location,locale){

	$(container).text('Please wait. Loading weather...');

	$.get( './weather/gwproxy2.php?weather=' + encodeURI(location) + '&hl='+encodeURI(locale), function(xml) {

		function addForecastDiv( day, condition, temp, icon ){
			
			daydiv = $("<div class='day'></div>");
			daydiv.append( "<div class='name'>" + day + "</div>" );
			daydiv.append( "<img src='http://www.google.com/" + icon + "' />" );
			
			daydiv.append( "<p class='condition'>" + condition + "</p>" );
			daydiv.append( "<p class='temp'>" + temp + "</p>");
			$(container).append(daydiv);
			
		}

		$(container).text('');
		
		var t_unit = '&deg;F';

		if( $(xml).find('forecast_information').find('unit_system').attr('data') == 'SI' )
			t_unit = '&deg;C';
	
		addForecastDiv(
			'Sada',
			$(xml).find('current_conditions').find('condition').attr('data') + '<br/>', 
			//$(xml).find('current_conditions').find('humidity').attr('data') + '<br/>' + 
			//$(xml).find('current_conditions').find('wind_condition').attr('data'),
			//$(xml).find('current_conditions').find('temp_f').attr('data') + '&deg;F, ' + 
			$(xml).find('current_conditions').find('temp_c').attr('data') + '&deg;C',
			$(xml).find('current_conditions').find('icon').attr('data')
		);

		$(xml).find('forecast_conditions').each(function(){
			addForecastDiv(
				$(this).find('day_of_week').attr('data'),
				$(this).find('condition').attr('data'),
				'<span style="color:red">' + $(this).find('high').attr('data') + '</span>' + t_unit + ' <br/><span style="color:blue"> ' + 
				$(this).find('low').attr('data') + t_unit + '</span>',
				$(this).find('icon').attr('data')
			);
		});
		/////////
		//alert('ggggg');
		$('#weatherdisplay').append("<div style='clear:both;'></div>");
		/////////

	},'xml');

}


