$(document).ready(function(){
	
	$.ajax({
		type: "GET",
	    //dataType: "xml",
		url: "/snowheight.php",
		success: parseXml

	});
});


function parseXml(xml){
	
	venue = "";
	
	$(document).find(".snow-height").each(function(){
		$(this).find("p").each(function(){
			
			venue = $(this).text();
			
		});
	});
	
	snowHeight = -1;
	
	$(xml).find("skiinfo_swc4_basic").each(function(){
		
		resort = "";
		
		$(this).find("resort").each(function(){
			
			resort = $(this).text();
			
		});
		
		
		if (jQuery.trim(venue) == jQuery.trim(resort)){
			
			$(this).find("station").each(function(){
				
				if ($(this).attr("type") == "top"){
				
					$(this).find("snow_total_cm").each(function(){
						
						snowHeight = $(this).text();
						
					});
					
				}
				
			});
		
		}
			
	});

	$(document).find(".snow-height").each(function(){
		$(this).find("p").each(function(){

			if (snowHeight > 0){
				$(this).html("<strong>Snow Height: </strong>"+snowHeight+"cm");
			}
			
		});
	});

}
