$(document).ready(function(){

	$.get("/views/generated/_xml/weather.xml",{},function(xml){
		
		// build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<ul>';

		// run the function for each day tag in the XML file
		$('day',xml).each(function(i) {
			date = $(this).find("date").text();
			temperature = $(this).find("weathervalue").text();
			condition = $(this).find("condition").text();
			image = $(this).find("image").text();

			// build <li> data and store in string
			mydata = BuildWeatherHTML(date,temperature,condition,image);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</ul>';
		
		// update the DIV called weatherBlock with the HTML string
		$("#weatherBlock").html(myHTMLOutput);
		
		jQuery.each(jQuery.browser, function(i, val) {
			if(i=="msie" && (jQuery.browser.version.substr(0,3)=="6.0" || jQuery.browser.version.substr(0,3)=="5.5")){
				$("#weatherBlock img").each(function(i){
					$(this).attr("src_ie6", $(this).attr("src"));
					$(this).attr("src", "");
					this.onload = function(){$(this).ifixpng()};
					$(this).attr("src", $(this).attr("src_ie6"));
				});
			}
		});
	});

});

function BuildWeatherHTML(date,temperature,condition,image) {

	// Build HTML string and return
	output = '';
	output += '<li>';
	output += '<a href="/?event=action.searchevents&dateSelectFrom='+date+'&isdateflag=yes">more.</a>';
	output += '<span>'+ temperature +' <img src="/images/weather/' + weather_image_prefix + image +'"></span>';
	output += '</li>';
	return output;
}