/* <![CDATA[ */
function f2c(t) {
	if(isNaN(t)){
		return t;
	}else return Math.round((t-32)*5/9);
}// Conversion Fahrenheit->Celsius

function Get_Meteo(id, lang, unite){
	if(id!=''){
		if(unite != "m"){
			degre = "&deg;F";
		}else{
			degre = "&deg;C";
		}
		$.getJSON('xml/get_meteo.php?city='+id+"&lang="+lang, function(data) {
			var actual_data = '';
			var have_weather = false;
			$.each(data, function(key, val) {
				if(key == "current_weather"){
					have_weather = true;
					$("#actual-icon").html('<img src="'+val.icon+'" width="80" height="80" alt="'+val.condition+'" title="'+val.condition+'" />');
					if(unite == "m" && lang == "en"){
						val.low = f2c(val.low);
						val.high = f2c(val.high);
					}
					var info = '';
					if(unite != "m"){
						info = '<h1>'+val.temp_f + degre+'</h1>';
					}else{
						info = '<h1>'+val.temp_c + degre+'</h1>';
					}
					info += '<p><span class="temp-min">' +  strmin + ' : ' + val.low + degre + '</span><br />';
					info += '<span class="temp-max">' + strmax + ' : ' + val.high + degre + '</span></p>';
					$("#actual-info").html(info);
					actual_data += val.condition + '<br />'  + val.wind_condition + '<br />' + val.humidity +'<br />';
					$("#actual-data").html(actual_data);
				}else if(key == "forecast_weather"){
					for(i = 1; i < val.length; i++){
						forecast = val[i];
						if(unite == "m" && lang == "en"){
							forecast.low = f2c(forecast.low);
							forecast.high = f2c(forecast.high);
						}
						$("#prev-day-title"+ parseInt(i-1)).html(forecast.day_of_week + ' '+forecast.day);
						$("#prev-day-icon"+ parseInt(i-1)).html('<img src="'+forecast.icon+'" width="40" height="40" alt="'+forecast.condition+'" title="'+forecast.condition+'" />');
						var prev_temp = '<span class="temp-min">'+forecast.low+degre+'</span> / <span class="temp-max">'+forecast.high+degre+'</span>';
						$("#prev-day-temp"+ parseInt(i-1)).html(prev_temp);
					}
				}
			});
			if(have_weather){
				$("#donnee-meteo").show();
				$("#rub_meteo").show();
			}
		});
	}
	return false;
}

/* ]]> */

