(function($){
	
	$.fn.weatherHourly = function(zip, options){
		var defaults = {
			imageurl: "",
			dynurl: ""
		};
		var options = $.extend(defaults, options);

		return this.each(function(i, e){
			var $e = $(e);

			// Validate
			if (zip == null)
				return false;

			try {
				$.jsonp({
      				url: ""+options.dynurl+"/weather/forecast/hourly/",
					data: {z : zip},
					context: document.body
				});
			} catch (error) {  
				//do nothing  
			}  
		});
	};

	$.fn.weatherhourlyCallback = function (data){
		var obj = $.parseJSON(unescape(data));
		if (typeof obj.DATA[0][0] != undefined && !(/^\s*$/).test(obj.DATA[0][0])) {
			$('#hourlyForecast').html('').append(obj.DATA[0][0]);
		}
	}

	//weatheralert() - used for body of "Alerts" tab
	$.fn.weatheralert = function(zip, options){
		var defaults = {
			imageurl: "",
			dynurl: ""
		};
		var options = $.extend(defaults, options);

		return this.each(function(i, e){
			var $e = $(e);

			// Validate
			if (zip == null)
				return false;

			try {
				$.jsonp({
      				url: ""+options.dynurl+"/weather/alerts/",
					data: {z : zip},
					context: document.body
				});
			} catch (error) {  
				//do nothing  
			}  
			
		});
	};

	$.fn.weatheralertCallback = function (data){
		var obj = $.parseJSON(unescape(data));
		if (typeof obj.DATA[0][0] != undefined && !(/^\s*$/).test(obj.DATA[0][0])) {
			$('#weatherAlert').html('').append(obj.DATA[0][0]);
		}
	}

	//checkWeatherAlerts() - used for "Local Weather Alerts" box at top of each tab
	$.fn.checkWeatherAlerts = function(zip, options){
		var defaults = {
			dynurl: ""
		};
		var options = $.extend(defaults, options);
		
		return this.each(function(i, e){
			var $e = $(e);
			// Validate
			if (zip == null) {
				return false;
			}

			try {
				$.jsonp({
      				url: ""+options.dynurl+"/weather/alertsmodule/",
					data: {z : zip},
					context: document.body
				});
			} catch (error) {  
				//do nothing  
			}  
		});
	};

	$.fn.checkWeatherAlertsCallback = function (data){
		var objBox = $.parseJSON(unescape(data));
		if (typeof objBox.DATA[0][0] != undefined && !(/^\s*$/).test(objBox.DATA[0][0])) {
			$('#localAlertsBox').html('').append(objBox.DATA[0][0]).css('display', 'block');
		}
	}

	$.fn.weatherTodaysForecast = function(zip, options){
		var defaults = {
			imageurl: ""
		};
		var options = $.extend(defaults, options);

		return this.each(function(i, e){
			var $e = $(e);

			// Validate
			if (zip == null)
				return false;

			$.get('/weather/feeds/'+zip.substring(0,1)+'/forecast/' + zip + '_full.xml', function(xml){
				var json = $.xml2json(xml);

				$('#todaysForecast').find("p").html(json.data.days.day[0].statement)

			});
		});
	};

})(jQuery);

