(function(a){a.extend({simpleWeather:function(b){var b=a.extend({zipcode:"76309",location:"",unit:"f",success:function(d){},error:function(d){}},b);var c="http://query.yahooapis.com/v1/public/yql?format=json&diagnostics=true&callback=?&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=";if(b.location!=""){c+='select * from weather.forecast where location in (select id from weather.search where query="'+b.location+'") and u="'+b.unit+'"'}else{if(b.zipcode!=""){c+='select * from weather.forecast where location in ("'+b.zipcode+'") and u="'+b.unit+'"'}else{b.error("No location given.");return false}}a.getJSON(c,function(d){if(d!=null&&d.query.results!=null){a.each(d.query.results,function(f,e){if(e.constructor.toString().indexOf("Array")!=-1){e=e[0]}currentDate=new Date();sunRise=new Date(currentDate.toDateString()+" "+e.astronomy.sunrise);sunSet=new Date(currentDate.toDateString()+" "+e.astronomy.sunset);if(currentDate>sunRise&&currentDate<sunSet){timeOfDay="d"}else{timeOfDay="n"}wind=e.wind.direction;if(wind>338){windDirection="N"}else{if(wind>=0&&wind<24){windDirection="N"}else{if(wind>=24&&wind<69){windDirection="NE"}else{if(wind>=69&&wind<114){windDirection="E"}else{if(wind>=114&&wind<186){windDirection="SE"}else{if(wind>=186&&wind<204){windDirection="S"}else{if(wind>=204&&wind<249){windDirection="SW"}else{if(wind>=249&&wind<294){windDirection="W"}else{if(wind>=294&&wind<338){windDirection="NW"}}}}}}}}}var g={title:e.item.title,temp:e.item.condition.temp,units:{temp:e.units.temperature,distance:e.units.distance,pressure:e.units.pressure,speed:e.units.speed},currently:e.item.condition.text,high:e.item.forecast[0].high,low:e.item.forecast[0].low,forecast:e.item.forecast[0].text,wind:{chill:e.wind.chill,direction:windDirection,speed:e.wind.speed},humidity:e.atmosphere.humidity,pressure:e.atmosphere.pressure,rising:e.atmosphere.rising,visibility:e.atmosphere.visibility,sunrise:e.astronomy.sunrise,sunset:e.astronomy.sunset,description:e.item.description,thumbnail:"http://l.yimg.com/a/i/us/nws/weather/gr/"+e.item.condition.code+timeOfDay+"s.png",image:"/img/weather/"+e.item.condition.code+".png",tomorrow:{high:e.item.forecast[1].high,low:e.item.forecast[1].low,forecast:e.item.forecast[1].text,date:e.item.forecast[1].date,day:e.item.forecast[1].day,image:"http://l.yimg.com/a/i/us/nws/weather/gr/"+e.item.forecast[1].code+"d.png"},city:e.location.city,country:e.location.country,region:e.location.region,updated:e.item.pubDate,link:e.item.link};b.success(g)})}else{if(d.query.results==null){b.error("Invalid location given.")}else{b.error("Weather could not be displayed. Try again.")}}});return this}})})(jQuery);
