// Time stuff
var sydneyTime = new Date(Date.parse("Feb, 26 2012 4:36:53"));
DOW = ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"];
function display_time(){
hour = sydneyTime.getHours();
minute = sydneyTime.getMinutes();
second = sydneyTime.getSeconds();
temp = "" + DOW[sydneyTime.getDay()] + " " + sydneyTime.getDate() + ", ";
temp += ((hour < 10) ? "0" : "") + hour;
temp += ((minute < 10) ? ":0" : ":") + minute;
document.getElementById("datetime").innerHTML = temp;
jQuery("#weather_widget").css('display', 'block');
}
function inc_time(){
sydneyTime = new Date(sydneyTime.getTime() + 60000);
display_time();
setTimeout("inc_time()",60000);
}
// Weather stuff, Set Sydney location
jQuery.cookie = function(name, value, options) {
if(name=='loc_longitude') return 151.206207;
else if (name=='loc_latitude') return -33.900056;
else if (name=='loc_country') return 'Australia';
else if (name=='loc_region') return 'New South Wales';
else if (name=='loc_city') return 'Sydney, NSW';
else if (name=='loc_country_code') return 'AU';
else return undefined;
}
jQuery("document").ready(function() {
// gestion de la date et l'heure
inc_time();
// et on lancec la récup de la météo
getWeather();
});
function getWeather() {
var latitude = jQuery.cookie('loc_latitude');
var longitude = jQuery.cookie('loc_longitude');
var loc_conditions = jQuery.cookie('loc_conditions');
var loc_conditions_img = jQuery.cookie('loc_conditions_img');
var loc_temp = jQuery.cookie('loc_temp');
var loc_humidity = jQuery.cookie('loc_humidity');
if (loc_conditions && loc_conditions_img) {
setConditions(loc_conditions, loc_conditions_img, loc_temp, loc_humidity);
} else {
var url = "http://ws.geonames.org/findNearByWeatherJSON?lat=" + latitude + "&lng=" + longitude + "&callback=?";
jQuery.getJSON(url, function(data) {
var clouds = data.weatherObservation.clouds;
var weather = data.weatherObservation.weatherCondition;
var temp = data.weatherObservation.temperature;
var humidity = data.weatherObservation.humidity;
var conditions_img = getConditions(clouds, weather);
var conditions = '';
if (weather == 'n/a') {
if (clouds == 'n/a') {
conditions = 'fine';
} else {
conditions = clouds;
}
} else {
conditions = weather;
}
jQuery.cookie('loc_conditions', conditions);
jQuery.cookie('loc_conditions_img', conditions_img);
jQuery.cookie('loc_temp', temp);
jQuery.cookie('loc_humidity', humidity);
setConditions(conditions, conditions_img, temp, humidity);
});
}
}
function getConditions(clouds, weather) {
if (weather == 'n/a') {
switch (clouds) {
case 'n/a':
return 'sunny.gif';
case 'clear sky':
return 'sunny.gif';
case 'few clouds':
return 'partly_cloudy.gif';
case 'scattered clouds':
return 'partly_cloudy.gif';
case 'broken clouds':
return 'partly_cloudy.gif';
default:
return 'cloudy.gif';
}
} else {
weather = weather.replace('light ', '').replace('heavy ', '').replace(' in vicinity', '');
switch(weather) {
case 'drizzle':
return 'rain.gif';
case 'rain':
return 'rain.gif';
case 'snow':
return 'snow.gif';
case 'snow grains':
return 'sleet.gif';
case 'ice crystals':
return 'icy.gif';
case 'ice pellets':
return 'icy.gif';
case 'hail':
return 'sleet.gif';
case 'small hail':
return 'sleet.gif';
case 'snow pellets':
return 'sleet.gif';
case 'unknown precipitation':
return 'rain.gif';
case 'mist':
return 'mist.gif';
case 'fog':
return 'fog.gif';
case 'smoke':
return 'smoke.gif';
case 'volcanic ash':
return 'smoke.gif';
case 'sand':
return 'dust.gif';
case 'haze':
return 'haze.gif';
case 'spray':
return 'rain.gif';
case 'widespread dust':
return 'dust.gif';
case 'squall':
return 'flurries.gif';
case 'sandstorm':
return 'dust.gif';
case 'duststorm':
return 'dust.gif';
case 'well developed dust':
return 'dust.gif';
case 'sand whirls':
return 'dust.gif';
case 'funnel cloud':
return 'flurries.gif';
case 'tornado':
return 'storm.gif';
case 'waterspout':
return 'storm.gif';
case 'showers':
return 'storm.gif';
case 'thunderstorm':
return 'thunderstorm.gif';
default:
if (weather.indexOf("rain")) {
return 'rain.gif';
} else if (weather.indexOf("snow")) {
return 'snow.gif';
} else if (weather.indexOf("thunder")) {
return 'thunderstorm.gif';
} else if (weather.indexOf("dust")) {
return 'dust.gif';
} else {
return 'sunny.gif';
}
}
}
}
function setConditions(conditions, conditions_img, temp, humidity) {
var country = jQuery.cookie('loc_country');
var region = jQuery.cookie('loc_region');
var city = jQuery.cookie('loc_city');
var loc_country_code = jQuery.cookie('loc_country_code');
if (loc_country_code == 'US') {
temp = parseInt(temp) + 32;
temp_type = "F";
} else {
temp_type = "C";
}
jQuery("
" + city + "
").insertBefore("#datetime"); jQuery("#weather_widget").append("" + temp + "° " + temp_type + ", " + humidity + "% hum.
"); jQuery("#weather_widget").css('display', 'block'); }