(function($){var CONST={US_States:{AK:"Alaska",AL:"Alabama",AR:"Arkansas",AS:"American Samoa",AZ:"Arizona",CA:"California",CO:"Colorado",CT:"Connecticut",DC:"District of Columbia",DE:"Delaware",FL:"Florida",FM:"Federated States of Micronesia",GA:"Georgia",GU:"Guam",HI:"Hawaii",IA:"Iowa",ID:"Idaho",IL:"Illinois",IN:"Indiana",KS:"Kansas",KY:"Kentucky",LA:"Louisiana",MA:"Massachusetts",MD:"Maryland",ME:"Maine",MH:"Marshall Islands",MI:"Michigan",MN:"Minnesota",MO:"Missouri",MP:"Northern Mariana Islands",MS:"Mississippi",MT:"Montana",NC:"North Carolina",ND:"North Dakota",NE:"Nebraska",NH:"New Hampshire",NJ:"New Jersey",NM:"New Mexico",NV:"Nevada",NY:"New York",OH:"Ohio",OK:"Oklahoma",OR:"Oregon",PA:"Pennsylvania",PR:"Puerto Rico",PW:"Palau",RI:"Rhode Island",SC:"South Carolina",SD:"South Dakota",TN:"Tennessee",TX:"Texas",UT:"Utah",VA:"Virginia",VI:"Virgin Islands",VT:"Vermont",WA:"Washington",WI:"Wisconsin",WV:"West Virginia",WY:"Wyoming"}};function WeatherService(namespace){this.namespace=namespace;var initVars={weatherCityData:[],ACListener:{},currentLocId:"",currentCityString:"",serviceTriggered:false,UPDATE_HEADER_ACTION:"UPDATE_HEADER",SERVICE_URL_WEATHER_JSONP:"/weather/feed/getWeatherJsonP",SERVICE_URL_LOCATION_JSONP:"/weather/feed/getLocationIdJsonP",SERVICE_URL_WEATHER_HTML:"/weather/feed/getWeatherHtml",SERVICE_URL_LOCATION_REGION_JSON:"/weather/feed/getLocationRegionCodeJson",SERVICE_URL_CITY_DATA:"/weather/feed/getWeatherCityData",SERVICE_URL_MARINE_JSON:"/weather/feed/getMarineLocationsJson",SERVICE_URL_SKI_RESORTS_JSON:"/weather/feed/getSkiResortsJson",SERVICE_URL_SKI_COND_JSON:"/weather/feed/getSkiConditionJson",SERVICE_URL_AIRPORT_LOCATION_JSON:"/weather/feed/getAirportLocationIdJson",SERVICE_URL_AIRPORT_DELAY_JSON:"/weather/feed/getAirportDelayJson",PAGE_URL_YOUR_WEATHER:"/weather/your-weather/index.html",PAGE_URL_SEARCH_RESULTS:"/weather/search-results/index.html",PATH_WEATHER_ICON_IMAGE:(window.FOX_DomainPath||"")+"/static/all/img/weather/icons_60x60/",PATH_WEATHER_ICON_IMAGE_LARGE:(window.FOX_DomainPath||"")+"/static/all/img/weather/icons_96x96/",WEATHER_ICON_IMAGE_EXT:".png",WEATHER_DEFAULT_LOCATION:"USNY0996",WEATHER_COOKIE_DOMAIN:"foxnews.com",MSG_DEFAULT_ERROR:"Data unavailable. Please check back again soon.",MSG_AIRPORT_CODE_ERROR:"Please enter a valid 3- or 4-digit airport code.",MSG_AIRPORT_NOT_FOUND_ERROR:"No airport results found.  Please try again.",TXT_DEFAULT_SEARCH_FIELD:"Enter city or zip code",TXT_HEADER_SEARCH_FIELD:"Enter city or zip",TXT_AIRPORT_SEARCH_FIELD:"Enter airport code (IATA or ICAO)",LIST_SKI_CONDITIONS_ENABLED:"AK|AL|AZ|CA|CO|CT|IA|ID|IL|IN|MA|MD|ME|MI|MN|MO|MT|NC|ND|NH|NJ|NM|NV|NY|OH|OR|PA|RI|SD|TN|UT|VA|VT|WA|WI|WV|WY",LIST_MARINE_FORECAST_ENABLED:"AK|AL|AS|AZ|CA|CT|DC|DE|FL|FM|GA|GU|HI|LA|MA|MD|ME|MH|MS|NC|NJ|NY|OR|PA|PR|PW|RI|SC|TX|VA|VI|VT|WA"};var i;for(i in initVars){this[i]=initVars[i];}this.extService=new ExternalServices(this);}WeatherService.prototype={init:function(fn){var ws=this,initData='{"location":[{"loc_id":"USNY0996","zip":"10108","city":"New York","state":"NY"}]}';var trigger=function(data){ws.createWeatherLocationCookie(data);ws.renderWidget();if(typeof fn==="function"){fn();}};if(ws.weatherCookie("weatherloc")){var cookie=ws.weatherCookie("weatherloc"),weatherlocObj=this.createObjFromJSON(cookie);if(!weatherlocObj||!weatherlocObj.location||!weatherlocObj.location[0].loc_id){trigger(initData);}else{trigger(cookie);}}else{if(window.CONST_Akamai_GEO&&CONST_Akamai_GEO.countryCode==="US"){ws.getGeoLocation(function(data){trigger(data||initData);});}else{trigger(initData);}}},getGeoLocation:function(fn){var ws=this;var ret=function(info){if(typeof fn==="function"){fn(info);}};var zip=(function(){var obj=window.CONST_Akamai_GEO,range=obj.zipRange,zip=range.substring(0,5);return(!isNaN(zip))?zip:false;}());if(zip){ws.location_searchresults_callback=ws.location_search_callback=function(data){ret(data);};$.ajax({url:weather_service.SERVICE_URL_LOCATION_JSONP+"weather_service.location_searchresults_callback&jsonp=?",data:{zipOrLocation:zip},dataType:"jsonp",async:false});}else{ret(false);}},setExtData:function(location,info){this.extService._DataObj={location:location,info:this.createObjFromJSON(info)};this.extService.reloadWidgets();},weatherCookie:function(name,value,options){if(typeof value!=="undefined"){options=options||{};if(value===null){value="";options.expires=-1;}var expires="";if(options.expires&&(typeof options.expires==="number"||options.expires.toUTCString)){var date;if(typeof options.expires==="number"){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires="; expires="+date.toUTCString();}var path=options.path?"; path="+(options.path):"",domain=options.domain?"; domain="+(options.domain):"",secure=options.secure?"; secure":"";document.cookie=[name,"=",encodeURIComponent(value),expires,path,domain,secure].join("");}else{var cookieValue=null;if(document.cookie&&document.cookie!==""){var i,cookies=document.cookie.split(";");for(i=0;i<cookies.length;i++){var cookie=$.trim(cookies[i]);if(cookie.substring(0,name.length+1)===(name+"=")){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}},createWeatherDataCookie:function(locId,jsonString){var validateWeatherObj=this.createObjFromJSON(jsonString),weatherJSObj=validateWeatherObj.weatherData,city=weatherJSObj.cityName,country=weatherJSObj.country,tempHi=weatherJSObj.days[0].hi,tempLo=weatherJSObj.days[0].lo;if(validateWeatherObj&&city!==""&&country!==""){var expDate=new Date();if(tempHi===""||tempLo===""){expDate.setTime(expDate.getTime()+(60*1000));}else{expDate.setTime(expDate.getTime()+(2*60*60*1000));}this.weatherCookie("weatherdata_"+locId,jsonString,{expires:expDate,path:"/",domain:this.WEATHER_COOKIE_DOMAIN});}},createWeatherLocationCookie:function(jsonString){var expDate=new Date();expDate.setTime(expDate.getTime()+(1000*24*60*60*1000));this.weatherCookie("weatherloc",jsonString,{expires:expDate,path:"/",domain:this.WEATHER_COOKIE_DOMAIN});},createWeatherFavoritesCookie:function(favArray){var favIndex,favLocCookieString="",len=favArray.length;for(favIndex=0;len;favIndex++){favLocCookieString+=favArray[favIndex]+"|";}favLocCookieString=favLocCookieString.slice(0,-1);if(favLocCookieString!==""){var expDate=new Date();expDate.setTime(expDate.getTime()+(1000*24*60*60*1000));this.weatherCookie("weatherfavlocs",favLocCookieString,{expires:expDate,path:"/",domain:this.WEATHER_COOKIE_DOMAIN});}else{this.weatherCookie("weatherfavlocs","",{expires:-1,path:"/",domain:this.WEATHER_COOKIE_DOMAIN});}},getWeatherDataCookie:function(locId){return this.weatherCookie("weatherdata_"+locId);},createObjFromJSON:function(jsonString){if(jsonString!==""){return eval("("+unescape(jsonString).replace(/\s+/g," ")+")");}else{return null;}},createLocJSObj:function(data){if(!data.loc_id){return null;}var i,obj={loc_id:"",city:"",zip:"",state:"",country:""};for(i in data){var val=data[i];if(i==="city"){val=val.replace("`","'");}obj[i]=val;}obj.fullCityString=obj.city+(obj.loc_id.substr(0,2).toUpperCase()!=="US"&&(obj.country||obj.state))?(", "+obj.country):(", "+obj.state);return obj;},displayHeader:function(serviceDomain){var ws=this;if(this.serviceTriggered){return false;}else{this.serviceTriggered=true;}if(serviceDomain!="undefined"&&serviceDomain!=null){this.PAGE_URL_SEARCH_RESULTS=serviceDomain+this.PAGE_URL_SEARCH_RESULTS;this.PAGE_URL_YOUR_WEATHER=serviceDomain+this.PAGE_URL_YOUR_WEATHER;this.SERVICE_URL_LOCATION_JSONP=serviceDomain+this.SERVICE_URL_LOCATION_JSONP;this.SERVICE_URL_WEATHER_JSONP=serviceDomain+this.SERVICE_URL_WEATHER_JSONP;if(document.location.hostname.lastIndexOf(this.WEATHER_COOKIE_DOMAIN)==-1){this.WEATHER_COOKIE_DOMAIN=document.location.hostname;}}this.init(function(){ws.renderWidget();});},renderWidget:function(){$("body").data("weather-rendered",true);var ws=this;ws.serviceTriggered=true;setTimeout(function(){ws.renderHeaderWeather();ws.renderHeaderLocationChange();},500);},renderHeaderWeather:function(){var ws=this;var trigger=function(){var requestedLocationObj=ws.createObjFromJSON(ws.weatherCookie("weatherloc"));$(".portlet .weather.current-conditions").each(function(){ws.renderYourWeather(this,requestedLocationObj.location[0].loc_id,"weather_current");});};if(this.weatherCookie("weatherloc")){var weatherlocObj=this.createObjFromJSON(this.weatherCookie("weatherloc"));var locObject=this.createLocJSObj(weatherlocObj.location[0]);if(this.getWeatherDataCookie(locObject.loc_id)){this.headerDisplayAction(locObject.loc_id);ws.setExtData(locObject,this.getWeatherDataCookie(locObject.loc_id));$(document).ready(function(){ws.renderWeatherWidget(locObject.loc_id);});}else{this.fetchAndSaveWeatherJSONCookie(locObject.loc_id);}trigger();}else{this.init(function(){var weatherlocObj=ws.createObjFromJSON(ws.weatherCookie("weatherloc"));ws.fetchAndSaveWeatherJSONCookie(weatherlocObj.location[0].loc_id);trigger();});}},renderRightRailSearch:function(){var topRightRailHtml="<ul>"+this.generateRightRailSearch("yourweather")+"</ul>";document.write(topRightRailHtml);},generateRightRailSearch:function(ac_results_css_appendix){var ws=this,searchField="weatherInput_"+ac_results_css_appendix,rightRailHTML='<li><form method="get" action="'+ws.PAGE_URL_SEARCH_RESULTS+'" id="weather_search_form" class="form_1" onsubmit="weather_service.locationSearchAction(this,\'#'+searchField+'\');"><fieldset class="text_box"><div class="search-input-holder"><div class="preloader-img"></div><input type="text" name="searchTerm" id="'+searchField+'" onfocus="weather_service.searchFieldOnFocus(this);" onblur="weather_service.searchFieldOnBlur(this, \''+ws.TXT_DEFAULT_SEARCH_FIELD+'\');" class="weather_city_autocomplete_'+ac_results_css_appendix+' search_input no_spon" size="50" value="'+ws.TXT_DEFAULT_SEARCH_FIELD+'" name="keys"/></div><input type="submit" class="go" value=""/></fieldset></form></li>';return rightRailHTML;},renderWeatherWidget:function(locationId){var widgetElm=$("#weather-widget");if(widgetElm.size()===0){return false;}var ws=this,headerDataCookie=this.getWeatherDataCookie(locationId),useLgIcons=(widgetElm.hasClass("use-lg-icons"))?true:false,imgDim=(useLgIcons)?[96,96]:[60,60],useImgSrc=(useLgIcons)?ws.PATH_WEATHER_ICON_IMAGE_LARGE:ws.PATH_WEATHER_ICON_IMAGE;if(headerDataCookie){var headerDataObj=this.createObjFromJSON(headerDataCookie);var wdObj=headerDataObj.weatherData;var form=widgetElm.children("form");form.find("label, p.state").html(wdObj.cityName+((wdObj.stateShort.length>0)?", "+wdObj.stateShort:"")).unbind("click").click(function(){ws.gotoYourWeatherPage(locationId,wdObj.cityName,wdObj.stateShort);});var listElm=widgetElm.children("ul:first");listElm.children("li.section").each(function(i){var item=$(this);if(wdObj.days[i]){var dataSource=wdObj.days[i];var imgSrc=useImgSrc+dataSource.image+ws.WEATHER_ICON_IMAGE_EXT;var hiTemp=dataSource.hi;var lowTemp=dataSource.lo;if(i===0){item.find(".current").html(wdObj.currentTemp+"&#176;");}if(item.find(".media img").size()===0){item.find(".media").html("<img />");}item.find(".media img").css({width:imgDim[0]+"px",height:imgDim[1]+"px"}).each(function(){var elm=$(this);elm.css({opacity:"0",display:"inline"});if(!$.browser.opera){var img=new Image();img.onload=function(){elm.attr("src",imgSrc);animateFn.show(elm,{speed:300,type:"swing"});};img.src=imgSrc;}else{elm.css({backgroundImage:"none",display:"inline",opacity:"0"});elm.attr({src:imgSrc});animateFn.show(elm,{speed:300,type:"linear"});}});var hiLow="Hi "+((hiTemp.length>0)?hiTemp+"&#176;":"-")+" | Lo "+((lowTemp.length>0)?lowTemp+"&#176;":"-");item.children("div:first").children("span").html(hiLow);item.unbind("click").click(function(){ws.gotoYourWeatherPage(locationId,wdObj.cityName,wdObj.stateShort);});}});}if(widgetElm.data("setListeners")){return false;}widgetElm.data("setListeners",true);widgetElm.children("form").each(function(){var form=$(this);var search=form.find("#weather_widgetInput");var txt=search.attr("value");search.focus(function(){var elm=$(this);var val=elm.attr("value");elm.attr("value",(val===txt)?"":val);}).blur(function(){var elm=$(this);var val=elm.attr("value");elm.attr("value",(val==="")?txt:val);ws.locationSearchAction(this,"#weather_widgetInput",ws.UPDATE_HEADER_ACTION);});form.submit(function(){ws.locationSearchAction(this,"#weather_widgetInput",ws.UPDATE_HEADER_ACTION);return false;});});},searchFieldOnFocus:function(inputField){if(inputField.value===this.TXT_DEFAULT_SEARCH_FIELD||inputField.value===this.TXT_HEADER_SEARCH_FIELD){inputField.value="";}},searchFieldOnBlur:function(inputField,message){if(inputField.value===""){inputField.value=message;}},airportSearchAction:function(airportForm,airportLocId){var ws=this,regexp=new RegExp("^[a-zA-Z]{3,4}$"),reqAC=$("#airportCode").val();if(!reqAC.match(regexp)){showToConsole(ws.MSG_AIRPORT_CODE_ERROR);return false;}$.ajax({type:"GET",async:true,cache:true,url:ws.SERVICE_URL_AIRPORT_LOCATION_JSON,data:{airportCode:reqAC,cb:cacheBuster()},success:function(data){var parsed=ws.createObjFromJSON(data);if(parsed){if(parsed.location.length>0){var airportLocObj=ws.createLocJSObj(parsed.location[0]);$(airportForm).attr("action",ws.PAGE_URL_YOUR_WEATHER);$(airportLocId).attr("value",airportLocObj.loc_id);}else{showToConsole(ws.MSG_AIRPORT_NOT_FOUND_ERROR);return false;}}},error:function(){showToConsole(ws.MSG_AIRPORT_NOT_FOUND_ERROR);return false;}});},getSetLocationAction:function(location,callback){if(!location){return false;}var ws=this;var locIdEx=new RegExp("^[a-zA-Z]{4}[0-9]{4}$");var upToCommaEx=new RegExp("[^,]*");if(locIdEx.exec(location)&&typeof callback==="function"){ws.fetchAndSaveWeatherJSONCookie(location,false,function(data){callback(ws.createObjFromJSON(data));});}},locationSearchAction:function(locationForm,searchInputId,action){var ws=this,locIdEx=new RegExp("^[a-zA-Z]{4}[0-9]{4}$"),upToCommaEx=new RegExp("[^,]*");if(locIdEx.exec(ws.currentLocId)){$(locationForm).attr("action",ws.PAGE_URL_YOUR_WEATHER);$(searchInputId).attr("name","locId");$(searchInputId).attr("value",ws.currentLocId);if(action===ws.UPDATE_HEADER_ACTION){ws.fetchLocationJSON(ws.currentLocId);ws.renderWidget();}}else{var locSearchTerm=upToCommaEx.exec($(searchInputId).attr("value")),callbackFn="location_searchresults_callback";ws[callbackFn]=function(data){$(locationForm).attr("action",ws.PAGE_URL_SEARCH_RESULTS);var qStr,locationJson=ws.createObjFromJSON(data);if(locationJson){if(locationJson.location.length===1){var exactMatchObj=ws.createLocJSObj(locationJson.location[0]);if(action===ws.UPDATE_HEADER_ACTION){ws.fetchLocationJSON(exactMatchObj.loc_id);ws.renderWidget();}else{$(locationForm).attr("action",ws.PAGE_URL_YOUR_WEATHER);$(searchInputId).attr("name","locId");$(searchInputId).attr("value",exactMatchObj.loc_id);}}else{qStr="?"+$(searchInputId).attr("name")+"="+locSearchTerm[0].replace(/\s+/g,"+");window.location.href=ws.PAGE_URL_SEARCH_RESULTS+qStr;}}else{qStr="?"+$(searchInputId).attr("name")+"="+locSearchTerm[0].replace(/\s+/g,"+");window.location.href=ws.PAGE_URL_SEARCH_RESULTS+qStr;}};$.ajax({url:ws.SERVICE_URL_LOCATION_JSONP,data:{zipOrLocation:locSearchTerm[0],callback:ws.namespace+"."+callbackFn,cb:cacheBuster()},dataType:"script",async:true,cache:true});}},gotoYourWeatherPage:function(locId,city,state,country){var ws=this,yourWeatherURL=ws.PAGE_URL_YOUR_WEATHER+"?locId="+locId;window.location.href=yourWeatherURL;},renderYourWeather:function(divClass,locationId,weatherView){var ws=this;if(!locationId||locationId===""){locationId=ws.WEATHER_DEFAULT_LOCATION;}$.get(ws.SERVICE_URL_WEATHER_HTML,{locationId:locationId,weatherView:weatherView},function(data){$(divClass).html(data);});},renderSearchResults:function(divClass,searchTerm){var ws=this,callbackFn="location_searchresults_callback";ws[callbackFn]=function(data){var searchResultsHtml="";if(data){var resultsIndex,locationJson=ws.createObjFromJSON(data);if(locationJson){if(locationJson.location.length>1){searchResultsHtml+='<p class="results">Your search for <span class="city">'+searchTerm+'</span> returned multiple locations</p><p>Please click on the location you are looking for:</p><p class="sorted">Sorted alphabetically by city, state, country<span/></p><table>';for(resultsIndex=0;resultsIndex<locationJson.location.length;resultsIndex++){var matchingLocObj=ws.createLocJSObj(locationJson.location[resultsIndex]),locationLink=ws.PAGE_URL_YOUR_WEATHER+"?locId="+matchingLocObj.loc_id;if(resultsIndex%2===0){searchResultsHtml+='<tr class="even">';}else{searchResultsHtml+="<tr>";}searchResultsHtml+='<td><a href="'+locationLink+'">'+matchingLocObj.city+"</a></td><td>"+matchingLocObj.state+"</td><td>"+matchingLocObj.country+"</td></tr>";}searchResultsHtml+="</table>";}else{if(locationJson.location.length===1){var locObj=ws.createLocJSObj(locationJson.location[0]);ws.gotoYourWeatherPage(locObj.loc_id,locObj.city,locObj.state,locObj.country);}else{searchResultsHtml+='<p class="results">Sorry there are no results for <span class="city">'+searchTerm+"</span></p><p>Please try another search</p>";}}}else{searchResultsHtml+=ws.MSG_DEFAULT_ERROR;}}else{searchResultsHtml+=ws.MSG_DEFAULT_ERROR;}$(divClass).html(searchResultsHtml);};$.ajax({url:ws.SERVICE_URL_LOCATION_JSONP,data:({zipOrLocation:searchTerm,callback:ws.namespace+"."+callbackFn,cb:cacheBuster()}),dataType:"script",async:true,cache:true});},renderAirportDelayInfo:function(divClass,airportCode){var ws=this,aCode=airportCode.toUpperCase();$.get(ws.SERVICE_URL_AIRPORT_DELAY_JSON,{airportCode:aCode},function(data){if(data){var delayIndex,delayJson=ws.createObjFromJSON(data),airportDelayHtml="";if(delayJson.delayList.length){airportDelayHtml+='<div class="delay">';for(delayIndex=0;delayIndex<delayJson.delayList.length;delayIndex++){var delayInfo=delayJson.delayList[delayIndex].delayInfo,delayReason=delayJson.delayList[delayIndex].delayReason;airportDelayHtml+='<p><img alt="Exclamation" src="'+(window.FOX_DomainPath||"")+'/static/all/img/exclamation.png"/>Delay Information</p><p class="information">'+delayInfo+'</p><p class="reason">Delay Reason</p><p class="information">'+delayReason+"</p>";}airportDelayHtml+="</div>";}else{airportDelayHtml+='<div class="no-delay"><p><img alt="Exclamation" src="'+(widow.FOX_DomainPath||"")+'/static/all/img/exclamation.png"/>Delay Information</p><p class="information">No delays at '+aCode+" reported.</p></div>";}$(divClass).html(airportDelayHtml);}});},renderMarineForecast:function(divClass){var ws=this,marineHtml="";marineHtml+='<div class="marine-search"><h1><strong>Marine</strong> Forecast</h1><div class="location"><form action="" class="form_1" id="search_form4" method="get"><div id="marine-state-dropdown" class="list-type-dropdown"><p class="text title">Choose Your State</p><div class="drop_container holder"><input type="hidden" name="marineState" value="" /><p class="weather_dropdown current-value">- select -</p><ul>'+ws.generateStatesList(ws.LIST_MARINE_FORECAST_ENABLED)+'</ul></div><div class="clear"></div></div><div id="marine-cities-dropdown" class="list-type-dropdown"><p class="text title">Choose Marine Location</p><div class="drop_container holder"><input type="hidden" name="marineLocation" value="" /><p id="tide-cities-p" class="weather_dropdown current-value disabled">- select -</p><ul id="tide-cities-list"><li></li></ul></div><div class="clear"></div></div></form></div></div><div class="marine-result"></div>';$(divClass).html(marineHtml);$(".weather .marine-result").each(function(){ws.renderYourWeather(this,"USCA0638","weather_marine");});},renderTideLocationsDropdown:function(stateAbbr){var ws=this;if(stateAbbr!==""){$.ajax({type:"GET",async:true,cache:true,url:ws.SERVICE_URL_MARINE_JSON,data:{state:stateAbbr,cb:cacheBuster()},success:function(data,textStatus){var marineLocJson=ws.createObjFromJSON(data);if(marineLocJson){if(marineLocJson.marineLocations.length>0){ws.generateTideLocationsList(marineLocJson.marineLocations);}else{showToConsole(ws.MSG_DEFAULT_ERROR);return false;}}else{showToConsole(ws.MSG_DEFAULT_ERROR);return false;}}});}},generateTideLocationsList:function(locArrayObj){var i,tideLocDropdown="";if(locArrayObj!==null){for(i=0;i<locArrayObj.length;i++){var marineLocId=locArrayObj[i].loc_id,marineCity=locArrayObj[i].city;tideLocDropdown+='<li lang="'+marineLocId+'">'+marineCity+"</li>";}$("#tide-cities-list").html(tideLocDropdown);$("#tide-cities-p").removeClass("disabled");}else{tideLocDropdown+='<li lang=""></li>';$("#tide-cities-list").html(tideLocDropdown);$("#tide-cities-p").html("- select -");$("#tide-cities-p").addClass("disabled");}try{FOX.site.channel.listDropdown.init();}catch(err){}},generateStatesList:function(statesList){var i,ws=this,listHtml="",states=statesList.split("|");for(i=0;i<states.length;i++){listHtml+='<li lang="'+states[i]+'">'+CONST.US_States[states[i]]+"</li>";}return listHtml;},renderSkiConditions:function(divClass){var ws=this,skiHtml="";skiHtml+='<div class="ski-search"><h1><strong>Ski</strong> Conditions</h1><div class="location"><form action="" class="form_1" id="search_form5" method="get"><div id="ski-state-dropdown" class="list-type-dropdown"><p class="text title">Choose Your State</p><div class="drop_container holder"><input type="hidden" name="skiState" value="" /><p class="weather_dropdown current-value">- select -</p><ul>'+ws.generateStatesList(ws.LIST_SKI_CONDITIONS_ENABLED)+'</ul></div><div class="clear"></div></div><div id="ski-resorts-dropdown" class="list-type-dropdown"><p class="text title">Choose Ski Location</p><div class="drop_container holder"><input type="hidden" name="skiLocation" value="" /><p id="ski-resorts-p" class="weather_dropdown current-value disabled">- select -</p><ul id="ski-resorts-list"><li></li></ul></div><div class="clear"></div></div></form></div></div><div class="ski-result"></div>';$(divClass).html(skiHtml);$(".weather .ski-result").each(function(){ws.renderSkiCondResult(this,"303003");});},renderSkiResortsDropdown:function(stateAbbr){var ws=this;if(stateAbbr!==""){$.ajax({type:"GET",async:true,cache:true,url:ws.SERVICE_URL_SKI_RESORTS_JSON,data:{state:stateAbbr,cb:cacheBuster()},success:function(data,textStatus){var skiResortJson=ws.createObjFromJSON(data);if(skiResortJson){if(skiResortJson.skiResorts!==null&&skiResortJson.skiResorts.length>0){ws.generateSkiResortsList(skiResortJson.skiResorts);}else{return false;}}else{showToConsole(ws.MSG_DEFAULT_ERROR);return false;}}});}},generateSkiResortsList:function(locArrayObj){var i,skiResortsDropdown="";if(locArrayObj!==null){for(i=0;i<locArrayObj.length;i++){var skiResortId=locArrayObj[i].resort_id,skiResortName=locArrayObj[i].resort_name;skiResortsDropdown+='<li lang="'+skiResortId+'">'+skiResortName+"</li>";}$("#ski-resorts-list").html(skiResortsDropdown);$("#ski-resorts-p").removeClass("disabled");}else{skiResortsDropdown+='<li lang=""></li>';$("#ski-resorts-list").html(skiResortsDropdown);$("#ski-resorts-p").html("- select -");$("#ski-resorts-p").addClass("disabled");}try{FOX.site.channel.listDropdown.init();}catch(err){}},renderSkiCondResult:function(divClass,resortId){var ws=this;$.get(ws.SERVICE_URL_SKI_COND_JSON,{resortId:resortId},function(data){var skiCondJson=ws.createObjFromJSON(data),skiResultHtml=ws.generateSkiCondHtml(skiCondJson);$(divClass).html(skiResultHtml);});},generateSkiCondHtml:function(skiCondJson){var skiObj=skiCondJson.skiConditions,snowMin=skiObj.new_snow_min?skiObj.new_snow_min+" in":"N/A",surface=skiObj.surface_condition?skiObj.surface_condition:"N/A",lastSnowfall=skiObj.last_snow?skiObj.last_snow+"in":"N/A",prevSnowfall=skiObj.prev_snow?skiObj.prev_snow:"N/A",baseDepth="N/A";if(skiObj.base_min&&skiObj.base_max){baseDepth=skiObj.base_min+" of "+skiObj.base_max;}var skiHtml='<ul><li><p class="city-name">'+skiObj.resort_name+", "+skiObj.state+' Ski Report</p><div class="four-half"><table><tbody><tr><td class="first">Operating Status</td><td>'+skiObj.open_status+'</td></tr><tr class="even"><td class="first">Surface</td><td>'+surface+'</td></tr><tr><td class="first">Temperature</td><td>'+skiObj.temperature+' F</td></tr><tr class="even"><td class="first">New Snowfall</td><td>'+snowMin+'</td></tr><tr><td class="first">Last Snowfall</td><td>'+lastSnowfall+'</td></tr><tr class="even"><td class="first">Previous Snowfall</td><td>'+prevSnowfall+'</td></tr><tr><td class="first">Lifts Open</td><td>'+skiObj.lifts_open+" of "+skiObj.lifts_total+'</td></tr><tr class="even"><td class="first">Trails Open</td><td>'+skiObj.trails_open+" of "+skiObj.trails_total+'</td></tr><tr><td class="first">Grooming Trails</td><td>'+skiObj.groom_trails+" of "+skiObj.trails_total+'</td></tr><tr class="even"><td class="first">Base Depth</td><td>'+baseDepth+'</td></tr><tr><td class="first">Terrain</td><td>'+skiObj.terrain+'&#37;</td></tr><tr class="even"><td class="first">Snow Made</td><td>'+skiObj.snow_made+'&#37;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr class="even"><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr></tbody></table></div></li></ul>';return skiHtml;},addToFavorites:function(locId){if(this.weatherCookie("weatherfavlocs")){var favLocationArray=(this.weatherCookie("weatherfavlocs")).split("|");if(favLocationArray.length<5){var favIndex,saveFavorite=true;for(favIndex=0;favIndex<favLocationArray.length;favIndex++){if(favLocationArray[favIndex]===locId){alert("You have already saved this location to My Favorites.");saveFavorite=false;}}if(saveFavorite){favLocationArray[favLocationArray.length]=locId;this.createWeatherFavoritesCookie(favLocationArray);this.renderFavorites();}}else{alert("You have 5 saved locations in My Favorites. Please remove one from My Favorites to save this location.");}}else{var newFavCookieArray=new Array(locId);this.createWeatherFavoritesCookie(newFavCookieArray);this.renderFavorites();}},removeFavorite:function(locId){if(this.weatherCookie("weatherfavlocs")){var favIndex,favLocationArray=(this.weatherCookie("weatherfavlocs")).split("|");for(favIndex=0;favIndex<favLocationArray.length;favIndex++){if(favLocationArray[favIndex]===locId){favLocationArray.splice(favIndex,1);break;}}this.createWeatherFavoritesCookie(favLocationArray);}$("#li_"+locId).remove();},generateFavoritesHtml:function(weatherObj){var dataObj=weatherObj.weatherData,stateToDisplay=dataObj.stateShort;if(dataObj.locationId.substr(0,2)!=="US"){stateToDisplay=dataObj.country;}var favHtml='<li id="li_'+dataObj.locationId+'"><div class="weather-img"><a href="#" onclick="weather_service.gotoYourWeatherPage(\''+dataObj.locationId+"','"+dataObj.cityName+"','"+dataObj.stateShort+"','"+dataObj.country+'\');return false;"><img alt="Weather" src="'+weather_service.PATH_WEATHER_ICON_IMAGE+dataObj.days[0].image+weather_service.WEATHER_ICON_IMAGE_EXT+'"/></a></div><div class="city-container"><h3>'+unescape(dataObj.cityName)+", "+stateToDisplay+'</h3><div class="desc"><p>'+dataObj.forecast+'</p></div></div><div class="degrees"><p>'+dataObj.days[0].hi+'&deg;&nbsp;<span class="low">'+dataObj.days[0].lo+'&deg;</span></p><a class="close" href="#" onclick="weather_service.removeFavorite(\''+dataObj.locationId+"');return false;\"/></div></li>";return favHtml;},renderFavorites:function(){var ws=this,favoritesHtml="<ul>";if(ws.weatherCookie("weatherfavlocs")){var favIndex,favLocationArray=(ws.weatherCookie("weatherfavlocs")).split("|");favoritesHtml+='<li><ul class="favorites">';for(favIndex=0;favIndex<favLocationArray.length;favIndex++){var favDataObj,favLocationId=favLocationArray[favIndex],favDataCookie=this.getWeatherDataCookie(favLocationId);if(favDataCookie){favDataObj=ws.createObjFromJSON(favDataCookie);favoritesHtml+=ws.generateFavoritesHtml(favDataObj);}else{var callbackFn="location_renderfavorites_callback";ws[callbackFn]=function(data){if(data){ws.createWeatherDataCookie(favLocationId,data);favDataObj=ws.createObjFromJSON(data);favoritesHtml+=ws.generateFavoritesHtml(favDataObj);}};$.ajax({url:ws.SERVICE_URL_WEATHER_JSONP,data:({locationId:favLocationId,callback:ws.namespace+"."+callbackFn,cb:cacheBuster()}),dataType:"script",async:true,cache:true});}}favoritesHtml+="</ul></li><li>&nbsp;</li>";}favoritesHtml+=this.generateRightRailSearch("myfav")+"</ul>";var favoritesObj=$(".component .weather.favorites");favoritesObj.html(favoritesHtml);$("ul.favorites li:last-child",favoritesObj).addClass("last");$("input[class*=weather_city_autocomplete_myfav]",favoritesObj).keyup(function(){ws.weatherCityAutoComplete(this);});},renderAirportSearch:function(){var airportHtml='<div class="weather airport-search"><h1><strong>Airport</strong> Delays</h1><ul><li><div><span class="text">'+this.TXT_AIRPORT_SEARCH_FIELD+'</span><form method="get" id="aiport_search" class="form_1" action="" onsubmit="return weather_service.airportSearchAction(this,\'#airportLocId\');"><fieldset class="text_box"><input type="text" id="airportCode" class="airport_input no_airport" size="50" value="" name="airportCode"/><input type="hidden" id="airportLocId" value="" name="locId"/><input type="submit" class="airport" value=""/></fieldset></form></div></li></ul></div>';document.write(airportHtml);},fetchAndSaveWeatherJSONCookie:function(locId,setAsCookie,callback){setAsCookie=(typeof setAsCookie==="boolean")?setAsCookie:true;var ws=this,callbackFn="location_weatherjsoncookie_callback";ws[callbackFn]=function(data){if(setAsCookie){ws.createWeatherDataCookie(locId,data);ws.renderWidget();}else{if(typeof callback==="function"){callback(data);}}};$.ajax({url:ws.SERVICE_URL_WEATHER_JSONP,data:({locationId:locId,callback:ws.namespace+"."+callbackFn,cb:cacheBuster()}),dataType:"script",async:true,cache:true});},fetchLocationJSON:function(locId){var ws=this,callbackFn="location_searchresults_callback";ws[callbackFn]=function(data){ws.createWeatherLocationCookie(data);};$.ajax({url:ws.SERVICE_URL_LOCATION_JSONP,data:({zipOrLocation:locId,callback:ws.namespace+"."+callbackFn,cb:cacheBuster()}),dataType:"script",async:true,cache:true});},fetchLocationRegionCode:function(locId){var ws=this,regionCode="";$.ajax({type:"GET",async:true,cache:true,url:ws.SERVICE_URL_LOCATION_REGION_JSON,data:{locationId:locId,cb:cacheBuster()},success:function(data,textStatus){if(data){var regionJson=ws.createObjFromJSON(data);regionCode=regionJson.regionCode;}},error:function(XMLHttpRequest,textStatus,errorThrown){showToConsole(ws.MSG_DEFAULT_ERROR);}});return regionCode;},weatherCityAutoComplete:function(element){var ws=this;ws.currentCityString="";var ACElementId=$(element).attr("id"),preloaderObj=$(".preloader-img:first",$(element).parent()),inputValue=$.trim($(element).val());if(inputValue.length<1){return ;}var cssValue=$(element).attr("class"),prefix="weather_city_autocomplete_",tempIndex=cssValue.indexOf(prefix)+prefix.length,appendix=cssValue.substr(tempIndex);tempIndex=appendix.indexOf(" ");if(tempIndex>0){appendix=appendix.substr(0,tempIndex);}var initial=inputValue.charAt(0).toLowerCase();if(initial.match(/[a-z]/)===null){return ;}if(typeof ws.weatherCityData[initial]==="undefined"){if(typeof ClientStorageManager==="undefined"){triggerAjaxCall(false);}else{var restrict=["cookie","msiestorage"];if(restrict.join("|").indexOf(ClientStorageManager.type.toLowerCase())===-1){ClientStorageManager.getItem(prefix+initial,function(storageData){if(storageData){var cities=eval(storageData);ws.weatherCityData[initial]=cities;triggerAutoComplete(cities);}else{triggerAjaxCall(true);}});}else{triggerAjaxCall(false);}}}else{triggerAutoComplete(ws.weatherCityData[initial]);}function triggerAjaxCall(useCSM){if(typeof ws.ACListener[ACElementId]==="undefined"){ws.ACListener[ACElementId]={init:false,fchar:initial,ajaxReady:true};}if(!ws.ACListener[ACElementId].ajaxReady){return ;}ws.ACListener[ACElementId].ajaxReady=false;$(preloaderObj).show();$.ajax({type:"GET",url:ws.SERVICE_URL_CITY_DATA,data:({cityNameInitial:initial,cb:cacheBuster()}),dataType:"text",cache:true,success:function(data,textStatus){if(data){var cities=eval(data.replace(/var cities\=/,""));if(useCSM){ClientStorageManager.saveItem({key:prefix+initial,value:cities,expire:7,success:function(returnObj){ws.weatherCityData[initial]=returnObj.value;},error:function(err){}});if(typeof ws.weatherCityData[initial]==="undefined"){ws.weatherCityData[initial]=cities;}triggerAutoComplete(ws.weatherCityData[initial]);}else{ws.weatherCityData[initial]=cities;triggerAutoComplete(ws.weatherCityData[initial]);}$(preloaderObj).fadeOut("slow");ws.ACListener[ACElementId].ajaxReady=true;}else{$(preloaderObj).hide();ws.ACListener[ACElementId].ajaxReady=true;showToConsole(ws.MSG_DEFAULT_ERROR);}},error:function(XMLHttpRequest,textStatus,errorThrown){$(preloaderObj).hide();ws.ACListener[ACElementId].ajaxReady=true;showToConsole(ws.MSG_DEFAULT_ERROR);}});}function triggerAutoComplete(cities){if(typeof ws.ACListener[ACElementId]==="undefined"){ws.ACListener[ACElementId]={init:false,fchar:initial,ajaxReady:true};}else{if(ws.ACListener[ACElementId].fchar!==initial){ws.ACListener[ACElementId].init=false;}}if(!ws.ACListener[ACElementId].init){$(element).autocomplete(cities,{max:20,width:193,selectFirst:false,resultsClass:"ac_results ac_results_"+appendix,formatItem:function(item){return item.t;}}).result(function(event,item){ws.currentLocId=item.id;ws.currentCityString=item.t;});ws.ACListener[ACElementId].init=true;ws.ACListener[ACElementId].fchar=initial;}}},renderHeaderLocationChange:function(){var ws=this,htmlArr=[],formTimeout=false;htmlArr.push('<div id="weather_loc_change" style="display:none;"><form action="#" method="get"><fieldset><legend>Weather</legend>');htmlArr.push('<input id="weather_headInput" type="text" name="searchTerm" value="Enter city or zip" />&nbsp;<input type="submit" name="submit" class="btn-smll" value="Go" />');htmlArr.push("</fieldset></form></div>");var htmlElm=$(htmlArr.join(""));htmlElm.find("form").each(function(){var elm=$(this),search=elm.find("#weather_headInput");search.focus(function(){ws.searchFieldOnFocus(this);clearTimeout(formTimeout);}).blur(function(){var elm=$(this),val=elm.attr("value");elm.attr("value",(val==="")?ws.TXT_HEADER_SEARCH_FIELD:val);formTimeout=setTimeout(function(){ws.changeHeaderLocation();},3000);});elm.submit(function(){clearTimeout(formTimeout);ws.locationSearchAction(elm,"#weather_headInput",ws.UPDATE_HEADER_ACTION);return false;});});$(".weather-search, #weather_corner").append(htmlElm);},changeHeaderLocation:function(){var info=$("#weather_cur_loc"),search=$("#weather_loc_change");if(info.is(":hidden")){search.css("display","none");info.css({opacity:"0",display:"inline"});animateFn.show(info,{speed:300,type:"swing"});}else{info.css("display","none");search.css({opacity:"0",display:"inline"});animateFn.show(search,{speed:300,type:"swing"});}},headerDisplayAction:function(locationId){var ws=this;var headerDataCookie=this.getWeatherDataCookie(locationId);if(headerDataCookie){var headerDataObj=this.createObjFromJSON(headerDataCookie),wdObj=headerDataObj.weatherData,htmlArr=[],imgSrc=this.PATH_WEATHER_ICON_IMAGE+wdObj.days[0].image+this.WEATHER_ICON_IMAGE_EXT;htmlArr.push('<div id="weather_cur_loc"><p><a href="#">Forecast:</a> <span class="degree">'+wdObj.currentTemp+'&#176; <img src="http://www.foxnews.com/static/all/img/clear.gif" style="width:24px; height:24px;"/></span> ');htmlArr.push('<span class="location">'+wdObj.cityName+'</span> <a href="#">edit</a></p></div>');var htmlElm=$(htmlArr.join(""));htmlElm.find("span.degree img").each(function(){var elm=$(this);elm.css({opacity:"0",display:"inline"});if(wdObj.days[0].image.length===0){elm.css("display","none");}else{if(!$.browser.opera){var img=new Image();img.onload=function(){elm.attr("src",imgSrc);animateFn.show(elm,{speed:300,type:"swing"});};img.src=imgSrc;}else{elm.css({backgroundImage:"none",display:"inline",opacity:"0"});elm.attr({src:imgSrc});animateFn.show(elm,{speed:300,type:"linear"});}}});htmlElm.find("a").each(function(){var aTag=$(this);var text=aTag.text().toLowerCase();aTag.click(function(){if(text.indexOf("forecast")>-1){ws.gotoYourWeatherPage(locationId,wdObj.cityName,wdObj.stateShort);}if(text.indexOf("edit")>-1){ws.changeHeaderLocation();}return false;});});$(".weather-search, #weather_corner").html(htmlElm);}}};function ExternalServices(root){this.root=root;this._DataObj=false;this._ExtWidgets=[];}ExternalServices.prototype={reloadWidgets:function(){var x,widgets=this._ExtWidgets,len=widgets.length;for(x=0;x<len;x++){var fn=widgets[x];if(typeof fn==="function"){fn();}}},setWidget:function(fn,execute){var EX=this;if(typeof fn==="function"){EX._ExtWidgets.push(fn);if(execute){fn();}}},getCurrentWeatherData:function(){},createForm:function(formElm){if(!formElm){return false;}var EX=this,root=this.root;formElm.each(function(){var form=$(this),search=form.find("#weather_widgetInput"),txt=search.attr("value");search.focus(function(){var elm=$(this),val=elm.attr("value");elm.attr("value",(val===txt)?"":val);}).blur(function(){var elm=$(this),val=elm.attr("value");elm.attr("value",(val==="")?txt:val);});form.submit(function(){root.locationSearchAction(this,"#weather_widgetInput",root.UPDATE_HEADER_ACTION);return false;});});}};function showToConsole(str){if(typeof (console)==="object"){console.log(str);}}function cacheBuster(freq){freq=freq||false;var date=new Date(),str=date.getFullYear().toString()+(date.getMonth()+1).toString()+date.getDate().toString();switch(freq){case"h":str+=(date.getHours()+1).toString();break;case"30m":str+=(date.getHours()+1).toString()+((date.getMinutes()%30===0)?"1":"0");break;default:str+=(date.getHours()+1).toString();}return str;}var weather_service=window.weather_service=new WeatherService("weather_service");var animateFn={isIE:function(){return $.browser.msie;},animate:function(elm,cfg){if(!this.isIE()){if(!cfg.speed){cfg.speed=300;}if(!cfg.type){cfg.type="swing";}elm.animate(cfg.css,cfg.speed,cfg.type,function(){if(cfg.callback){cfg.callback();}});}else{elm.css(cfg.css);elm.css("opacity","");if(cfg.callback){cfg.callback();}}},hide:function(elm,cfg){if(!elm){return false;}var i,cssObj={opacity:"0"};if(cfg.css){for(i in cfg.css){cssObj[i]=cfg.css[i];}}cfg.css=cssObj;this.animate(elm,cfg);},show:function(elm,cfg){if(!elm){return false;}var i,cssObj={opacity:"1"};if(cfg.css){for(i in cfg.css){cssObj[i]=cfg.css[i];}}cfg.css=cssObj;this.animate(elm,cfg);}};}(jQuery));
/*Fri Feb 03 14:16:40 EST 2012*/

