function AppendWeatherScript(url,clientLocation,container) {
    if (clientLocation) {
        var cdata = {};         
        cdata.lat = clientLocation.latitude;
        cdata.lng = clientLocation.longitude;
        if (clientLocation.address) {
            cdata.city = clientLocation.address.city;
            cdata.country = clientLocation.address.country;
            cdata.region = clientLocation.address.region;
            cdata.conuntry_code = clientLocation.address.conuntry_code;
        };
        url = url.replace(new RegExp("##lat##","g"), cdata.lat);
        url = url.replace(new RegExp("##lng##", "g"), cdata.lng);
        var scrpt = document.createElement("script");
        scrpt.type = "text/javascript";
        scrpt.src = url;
        if (container) container.appendChild(scrpt);
        else document.body.appendChild(scrpt);
    };
}

function ParceWeatherInfo(obj, container){
    if (obj) {
        var i = container.find(".icon-weather");
        var t = container.find(".tcontainer");
        //i.fadeOut();        
        container.fadeIn(1000);//, function () { if (result.icon) i.fadeIn(600); });
        
        obj = obj.Value;
        var result = {};
        result.IsNight = !obj.DayOrNight;
        if (obj.Weather) {
            result.title = obj.Weather.DayOfTheWeek + ', ' + String(obj.Weather.Date) + ', ' + (obj.Weather.CityName ? obj.Weather.CityName : '') + ', ' + String(obj.Weather.ProvinceName ? obj.Weather.ProvinceName : '');
            result.temperature = isNaN(obj.Weather.AverageTemperature) ? 0 : obj.Weather.AverageTemperature.toFixed();
            jQuery.cookie('cl_temp', result.temperature, { expires: 1, path: '/' });
            jQuery.cookie('cl_don', result.IsNight?"1":"0", { expires: 1, path: '/' });            
        } else if (!isNaN(obj.temperature)) {
            result.temperature = obj.temperature;
        };
        if (obj.WeatherOnline && obj.WeatherOnline.length > 0) {
            result.Date = obj.WeatherOnline[0].Date;
            result.MaxT = obj.WeatherOnline[0].MaxTemperature;
            result.MinT = obj.WeatherOnline[0].MinTemperature;
            result.IconNr = obj.WeatherOnline[0].Uv ? obj.WeatherOnline[0].Uv: 0;
            if (result.IconNr==8) result.IconNr = 7;
            result.IconAlt = obj.WeatherOnline[0].TextSymbol;
            result.icon = "http://www.zonneradar.nl/images/weather_symbols/" + (result.IsNight ? "moon_" : "sun_") + String(result.IconNr) + ".png";
            jQuery.cookie('cl_icn', result.IconNr, { expires: 1, path: '/' });            
        } else if (!isNaN(obj.icon)){
            result.icon = "http://www.zonneradar.nl/images/weather_symbols/" + (result.IsNight ? "moon_" : "sun_") + String(obj.icon) + ".png";
        };
        if (result.icon) {            
            i.find("img").remove();
            $("<img src=\"" + result.icon + "\" style='left:-10px;position:relative;width:75px;'/>").appendTo(i);
            i.attr("style", "background: none no-repeat scroll 0 0 transparent;");
            if (result.IconAlt) i.attr("title", result.IconAlt);            
        };
        if (result.title) container.attr("title", result.title);
        
        if (result.temperature) {
            t.html(String(result.temperature) + "&deg;");
            t.slideDown();
        } else t.slideUp();
        Cufon.replace('.cufonHV', { fontFamily: 'Helvetica Neue Hv', hover: true });
        
    } else container.hide(1);
}
