var tdWeather={};
(function(){tdWeather={_icons:{"01d":"clear-sky-d","02d":"few-clouds-d","03d":"scattered-clouds-d","04d":"broken-clouds-d","09d":"shower-rain-d","10d":"rain-d","11d":"thunderstorm-d","13d":"snow-d","50d":"mist-d","01n":"clear-sky-n","02n":"few-clouds-n","03n":"scattered-clouds-n","04n":"broken-clouds-n","09n":"shower-rain-n","10n":"rain-n","11n":"thunderstorm-n","13n":"snow-n","50n":"mist-n"},_currentRequestInProgress:!1,_currentItem:"",_currentLatitude:0,_currentLongitude:0,_currentPositionCacheKey:"",_currentLocationCacheKey:"",
_currentLocation:"",items:[],_is_location_open:!1,init:function(){jQuery(".td-icons-location").on("click",function(){!0!==tdWeather._currentRequestInProgress&&(tdWeather._currentRequestInProgress=!0,tdWeather._currentItem=tdWeather._getItemByBlockID(jQuery(this).data("block-uid")),navigator.geolocation&&navigator.geolocation.getCurrentPosition(tdWeather._updateLocationCallback,tdWeather._displayLocationApiError,{enableHighAccuracy:!0,timeout:1E7,maximumAge:6E5}),tdWeather._currentRequestInProgress=
!1)});jQuery(".td-weather-now").on("click",function(){!0!==tdWeather._currentRequestInProgress&&(tdWeather._currentRequestInProgress=!0,tdWeather._currentItem=tdWeather._getItemByBlockID(jQuery(this).data("block-uid")),tdWeather._currentItem.current_unit=1===tdWeather._currentItem.current_unit?0:1,tdWeather._renderCurrentItem())});jQuery(".td-manual-location-form").submit(function(a){a.preventDefault();!0!==tdWeather._currentRequestInProgress&&(tdWeather._currentRequestInProgress=!0,tdWeather._currentItem=
tdWeather._getItemByBlockID(jQuery(this).data("block-uid")),tdWeather._currentLocation=jQuery("input#"+jQuery(this).data("block-uid")).val(),tdWeather._updateLocationCallback2(tdWeather._currentLocation),tdWeather._currentRequestInProgress=!1,tdWeather._hide_manual_location_form())});jQuery(document).on("click",function(a){!0===tdWeather._is_location_open&&!0!==jQuery(a.target).hasClass("td-location-set-input")&&!0!==jQuery(a.target).hasClass("td-location-set-button")&&tdWeather._hide_manual_location_form()})},
addItem:function(a){tdWeather.items.push(a)},_updateLocationCallback:function(a){tdWeather._currentLatitude=a.coords.latitude;tdWeather._currentLongitude=a.coords.longitude;tdWeather._currentPositionCacheKey=a.coords.latitude+"_"+a.coords.longitude;tdLocalCache.exist(tdWeather._currentPositionCacheKey+"_today")?tdWeather._owmGetTodayDataCallback(tdLocalCache.get(tdWeather._currentPositionCacheKey+"_today")):jQuery.ajax({dataType:"jsonp",url:"https://api.openweathermap.org/data/2.5/weather?lat="+tdWeather._currentLatitude+
"&lon="+tdWeather._currentLongitude+"&units=metric&lang="+tdWeather._currentItem.api_language+"&appid="+tdWeather._currentItem.api_key,success:tdWeather._owmGetTodayDataCallback,cache:!0})},_owmGetTodayDataCallback:function(a){tdLocalCache.set(tdWeather._currentPositionCacheKey+"_today",a);tdWeather._currentItem.api_location=a.name;tdWeather._currentItem.today_clouds=tdUtil.round(a.clouds.all);tdWeather._currentItem.today_humidity=tdUtil.round(a.main.humidity);tdWeather._currentItem.today_icon=tdWeather._icons[a.weather[0].icon];
tdWeather._currentItem.today_icon_text=a.weather[0].description;tdWeather._currentItem.today_max[0]=tdUtil.round(a.main.temp_max,1);tdWeather._currentItem.today_max[1]=tdWeather._celsiusToFahrenheit(a.main.temp_max);tdWeather._currentItem.today_min[0]=tdUtil.round(a.main.temp_min,1);tdWeather._currentItem.today_min[1]=tdWeather._celsiusToFahrenheit(a.main.temp_min);tdWeather._currentItem.today_temp[0]=tdUtil.round(a.main.temp,1);tdWeather._currentItem.today_temp[1]=tdWeather._celsiusToFahrenheit(a.main.temp);
tdWeather._currentItem.today_wind_speed[0]=tdUtil.round(a.wind.speed,1);tdWeather._currentItem.today_wind_speed[1]=tdWeather._kmphToMph(a.wind.speed);tdLocalCache.exist(tdWeather._currentPositionCacheKey)?tdWeather._owmGetFiveDaysData(tdLocalCache.get(tdWeather._currentPositionCacheKey)):jQuery.ajax({dataType:"jsonp",url:"https://api.openweathermap.org/data/2.5/forecast?lat="+tdWeather._currentLatitude+"&lon="+tdWeather._currentLongitude+"&units=metric&lang="+tdWeather._currentItem.api_language+"&appid="+
tdWeather._currentItem.api_key,success:tdWeather._owmGetFiveDaysData,cache:!0})},_owmGetFiveDaysData:function(a){tdLocalCache.set(tdWeather._currentPositionCacheKey,a);for(var b=0;b<tdWeather._currentItem.forecast.length&&5!==b;b++){var c=tdWeather._currentItem.forecast[b];c.day_temp[0]=tdUtil.round(a.list[c.owm_day_index].main.temp_max);c.day_temp[1]=tdWeather._celsiusToFahrenheit(c.day_temp[0])}tdWeather._renderCurrentItem()},_renderCurrentItem:function(){var a=jQuery("#"+tdWeather._currentItem.block_uid),
b=tdWeather._currentLatitude,c=tdWeather._currentLongitude,e=tdWeather._currentLocation;a.find(".td-weather-city").html(tdWeather._currentItem.api_location);""===e&&0===b&&0===c&&a.find(".td-weather-city").html(tdWeather._currentItem.api_location);a.find(".td-weather-condition").html(tdWeather._currentItem.today_icon_text);b=a.find(".td-w-today-icon");b.removeClass();b.addClass("td-w-today-icon");b.addClass(tdWeather._currentItem.today_icon);b=tdWeather._currentItem.current_unit;c="kmh";e="C";1===
b&&(c="mph",e="F");a.find(".td-big-degrees").html(tdWeather._currentItem.today_temp[b]);a.find(".td-weather-unit").html(e);a.find(".td-w-high-temp").html(tdWeather._currentItem.today_max[b]);a.find(".td-w-low-temp").html(tdWeather._currentItem.today_min[b]);a.find(".td-w-today-humidity").html(tdWeather._currentItem.today_humidity+"%");a.find(".td-w-today-wind-speed").html(tdWeather._currentItem.today_wind_speed[b]+c);a.find(".td-w-today-clouds").html(tdWeather._currentItem.today_clouds+"%");for(c=
0;c<tdWeather._currentItem.forecast.length;c++)a.find(".td-day-"+c).html(tdWeather._currentItem.forecast[c].day_name),a.find(".td-degrees-"+c).html(tdWeather._currentItem.forecast[c].day_temp[b]);tdWeather._currentRequestInProgress=!1},_getItemByBlockID:function(a){for(var b=0;b<tdWeather.items.length;b++)if(tdWeather.items[b].block_uid===a)return tdWeather.items[b];return!1},_displayLocationApiError:function(a){if(1===a.code){if(tdDetect.isAndroid)tdWeather._show_manual_location_form();else if(tdDetect.isIos){alert("Please enable Location services for Safari Websites and reload the page. \n ---------------------- \nSettings > Privacy > Location Services");
return}tdWeather._show_manual_location_form()}tdWeather._show_manual_location_form()},_celsiusToFahrenheit:function(a){a=9*a/5+32;var b=tdUtil.round(a,1);return 99.9<b?tdUtil.round(a):b},_kmphToMph:function(a){return tdUtil.round(.621371192*a,1)},_show_manual_location_form:function(){tdWeather._currentItem=tdWeather._getItemByBlockID(tdWeather._currentItem.block_uid);jQuery("#"+tdWeather._currentItem.block_uid).find(".td-weather-set-location").addClass("td-show-location");jQuery(".td-manual-location-form input").focus();
tdWeather._is_location_open=!0},_hide_manual_location_form:function(){jQuery("#"+tdWeather._currentItem.block_uid).find(".td-weather-set-location").removeClass("td-show-location");tdWeather._is_location_open=!1},_updateLocationCallback2:function(a){tdWeather._currentLocationCacheKey=a;tdLocalCache.exist(tdWeather._currentLocationCacheKey+"_today")?tdWeather._owmGetTodayDataCallback2(tdLocalCache.get(tdWeather._currentLocationCacheKey+"_today")):(a="https://api.openweathermap.org/data/2.5/weather?q="+
encodeURIComponent(a)+"&lang="+tdWeather._currentItem.api_language+"&units=metric&appid="+tdWeather._currentItem.api_key,jQuery.ajax({dataType:"jsonp",url:a,success:tdWeather._owmGetTodayDataCallback2,cache:!0}))},_owmGetTodayDataCallback2:function(a){tdLocalCache.set(tdWeather._currentLocationCacheKey+"_today",a);tdWeather._currentItem.api_location=a.name;tdWeather._currentItem.today_clouds=tdUtil.round(a.clouds.all);tdWeather._currentItem.today_humidity=tdUtil.round(a.main.humidity);tdWeather._currentItem.today_icon=
tdWeather._icons[a.weather[0].icon];tdWeather._currentItem.today_icon_text=a.weather[0].description;tdWeather._currentItem.today_max[0]=tdUtil.round(a.main.temp_max,1);tdWeather._currentItem.today_max[1]=tdWeather._celsiusToFahrenheit(a.main.temp_max);tdWeather._currentItem.today_min[0]=tdUtil.round(a.main.temp_min,1);tdWeather._currentItem.today_min[1]=tdWeather._celsiusToFahrenheit(a.main.temp_min);tdWeather._currentItem.today_temp[0]=tdUtil.round(a.main.temp,1);tdWeather._currentItem.today_temp[1]=
tdWeather._celsiusToFahrenheit(a.main.temp);tdWeather._currentItem.today_wind_speed[0]=tdUtil.round(a.wind.speed,1);tdWeather._currentItem.today_wind_speed[1]=tdWeather._kmphToMph(a.wind.speed);tdLocalCache.exist(tdWeather._currentLocationCacheKey)?tdWeather._owmGetFiveDaysData2(tdLocalCache.get(tdWeather._currentLocationCacheKey)):jQuery.ajax({dataType:"jsonp",url:"https://api.openweathermap.org/data/2.5/forecast?q="+tdWeather._currentItem.api_location+"&lang="+tdWeather._currentItem.api_language+
"&units=metric&cnt=35&appid="+tdWeather._currentItem.api_key,success:tdWeather._owmGetFiveDaysData2,cache:!0})},_owmGetFiveDaysData2:function(a){tdLocalCache.set(tdWeather._currentLocationCacheKey,a);for(var b={},c=!0,e=Object.prototype.hasOwnProperty,d=0;d<a.list.length;d++)if(e.call(a.list[d],"dt")){c=a.list[d].dt;var f=td_date_i18n("Ymd",c);!1===e.call(b,f)?b[f]={timestamp:c,day_name:td_date_i18n("D",c),day_temp:[tdUtil.round(a.list[d].main.temp_max),tdUtil.round(tdWeather._celsiusToFahrenheit(a.list[d].main.temp_max))],
owm_day_index:d}:b[f].day_temp[0]<tdUtil.round(a.list[d].main.temp_max)&&(b[f].day_temp[0]=tdUtil.round(a.list[d].main.temp_max),b[f].day_temp[1]=tdUtil.round(tdWeather._celsiusToFahrenheit(a.list[d].main.temp_max)));c=!1}if(!1===c){tdWeather._currentItem.forecast=[];for(var g in b){if(5===tdWeather._currentItem.forecast.length)break;tdWeather._currentItem.forecast[tdWeather._currentItem.forecast.length]=b[g]}}tdWeather._renderCurrentItem()}}})();tdWeather.init();
