/** * @author Paul Chan / KF Software House  * http://www.kfsoft.info * * Version 0.5 * Copyright (c) 2010 KF Software House * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php * */var boxTemplate, stripTemplate;boxTemplate = "<div id='weather_today'>\		<div class='today_intro'>Your Weather for:</div>\		<div class='today'>{county}</div>\		<div class='today_detail'>\			<div class='today_therm'><img src='http://data.celticmediagroup.com/furniture/2011/yf/weather_therm.png' height='40'/></div>\			<div class='today_temp'>{temp}</div>\			<div class='today_icon'>{icon}</div>\			<div class='today_text'>{condition}<br/>{humidity}</div>\			<div class='clear'></div>\		</div>\	  </div>\	  <div id='forecast'>\		<div class='day'>{day1_name}<div class='day_content'>{day1_icon}<div class='low-high'><strong>&uarr; {day1_high}</strong><br/>&darr; {day1_low}</div></div></div>\		<div class='day'>{day2_name}<div class='day_content'>{day2_icon}<div class='low-high'><strong>&uarr; {day2_high}</strong><br/>&darr; {day2_low}</div></div></div>\		<div class='day'>{day3_name}<div class='day_content'>{day3_icon}<div class='low-high'><strong>&uarr; {day3_high}</strong><br/>&darr; {day3_low}</div></div></div>\		<div class='clear'></div>\	  </div>";	  stripTemplate = "<div id='weather_today_strip'>\		<div class='today_intro'>Your Weather for:</div>\		<div class='today'>{county}</div>\		<div class='today_detail'>\			<div class='detail_container'>\			<div class='today_therm'><img src='http://data.celticmediagroup.com/furniture/2011/yf/weather_therm.png' height='40'/></div>\			<div class='today_temp'>{temp}</div>\			<div class='today_icon'>{icon}</div>\			</div>\			<div class='detail_container'>\			<div class='today_text'>{condition}<br/>{humidity}</div>\			<div class='clear'></div>\			</div>\		</div>\	  </div>\	  <div id='forecast_strip'>\		<div class='day'><div class='day_icon'>{day1_icon}</div><div class='day_content'><div class='day_name'>{day1_name}</div><div class='day_cond'>{day1_cond}</div></div><div class='day_detail'><div class='high'>High: {day1_high}</div><div class='low'>Low: {day1_low}</div></div></div>\		<div class='day'><div class='day_icon'>{day2_icon}</div><div class='day_content'><div class='day_name'>{day2_name}</div><div class='day_cond'>{day2_cond}</div></div><div class='day_detail'><div class='high'>High: {day2_high}</div><div class='low'>Low: {day2_low}</div></div></div>\		<div class='day'><div class='day_icon'>{day3_icon}</div><div class='day_content'><div class='day_name'>{day3_name}</div><div class='day_cond'>{day3_cond}</div></div><div class='day_detail'><div class='high'>High: {day3_high}</div><div class='low'>Low: {day3_low}</div></div></div>\		<div class='clear'></div>\	  </div>"; (function($) {    var _options = null;	jQuery.fn.MyGoogleWeather = function(options) {		_options = $.extend({}, $.fn.MyGoogleWeather.defaults, options);		return this.each(function()		{			//load webfont			$("head").append("<link>"); 			css = $("head").children(":last");			css.attr({  				rel: "stylesheet", 				type: "text/css", 				href: "http://fonts.googleapis.com/css?family=" + getFontName(_options.GoogleFontFamily)			});						var o = $(this);			$.ajax({			  url: "/assets/weatherproxy.php",			  data: "c="+ _options.Location,			  success: function(data){					var doc = $.parseXML(data);					var $xml = $(doc);					var $current = $xml.find("current_conditions");					var location = $xml.find("forecast_information").find("city").attr("data");										var currentCondition = $current.find("condition").attr("data");					var currentHumidity = $current.find("humidity").attr("data");					var currentC = $current.find("temp_c").attr("data");					var currentF = $current.find("temp_f").attr("data");					var icon = $current.find("icon").attr("data");					icon = "http://www.google.com/"+ icon;										var template = _options.template;					template = template.replace(/{icon}/g, "<img src=" +icon +" />");										if (_options.bCelsius)						template = template.replace(/{temp}/g, "<span class=temperature>"+ currentC +"&deg;C"+ "</span>");					else						template = template.replace(/{temp}/g, "<span class=temperature>"+ currentF +"&deg;F"+ "</span>");					template = template.replace(/{location}/g, "<span class=location>"+ location + "</span>");					template = template.replace(/{condition}/g, "<span class=condition>"+ currentCondition+ "</span>");					template = template.replace(/{humidity}/g, "<span class=humidity>"+ currentHumidity+ "</span>");										//Loop through all forecast_conditions					var forecast_loop = 1;					$xml.find("forecast_conditions").each(function(){						var replaceCounty = new RegExp('\{county\}','g');						var replaceDay = new RegExp('\{day'+ forecast_loop +'_name\}','g');						var replaceIcon = new RegExp('\{day'+ forecast_loop +'_icon\}','g');						var replaceLow = new RegExp('\{day'+ forecast_loop +'_low\}','g');						var replaceHigh = new RegExp('\{day'+ forecast_loop +'_high\}','g');						var replaceCond = new RegExp('\{day'+ forecast_loop +'_cond\}','g');												var lowC = (5/9 * ($(this).find("low ").attr("data") - 32)).toFixed(0);						var highC = (5/9 * ($(this).find("high").attr("data") - 32)).toFixed(0);												template = template.replace(replaceCounty, _options.Location);						template = template.replace(replaceDay, $(this).find("day_of_week").attr("data"));						template = template.replace(replaceIcon, "<img src=http://www.google.com/" + $(this).find("icon").attr("data") +" />");						template = template.replace(replaceLow, lowC +"&deg;");						template = template.replace(replaceHigh, highC +"&deg;");						template = template.replace(replaceCond, $(this).find("condition").attr("data"));												forecast_loop += 1;					});										$(o).append(template);					$(o).css("fontFamily", _options.GoogleFontFamily + ",arial, serif");			  },			  error: function(){			  },			  cache:false			  			});		});	}	//default values	jQuery.fn.MyGoogleWeather.defaults = {		GoogleFontFamily: "Oswald",		Location:"Meath",		bCelsius: false,		template: "<TABLE><TR><TD>{location}<BR>{condition}<TD>{icon} <TD>{temp} </TABLE>"	};		function getFontName(str){		return str.replace(/ /g, '+');	}})(jQuery);
