$(document).ready(function(){
	//getJSON xml for crossdomain issues
	//Weather feed from Yahoo! Weather
    $.ajax({
        url: "http://query.yahooapis.com/v1/public/yql",
		type: "GET",
        dataType: "jsonp",
		data: {q:'select * from weather.forecast where location="ISXX0010" AND u="f"', format:"xml"},
		crossDomain:true,
        success: parseTheWeather
    });
	//tel aviv
	$.ajax({
        url: "http://query.yahooapis.com/v1/public/yql",
		type: "GET",
        dataType: "jsonp",
		data: {q:'select * from weather.forecast where location="ISXX0026" AND u="f"', format:"xml"},
		crossDomain:true,
        success: parseTheWeather
    });
});

function parseTheWeather(data, text, xhqr){

	//parse the data(string) as XML so you can traverse it
	var theXmlDoc = $.parseXML(data.results[0]);

	//check the city
	$(theXmlDoc).find('[nodeName="yweather:location"]').each(function(){
		if($(this).attr("city")=="Jerusalem") { //Jerusalem
			$(theXmlDoc).find('[nodeName="yweather:condition"]').each(function(){
				$(".temperature_icon.jeru").html('<img src="http://l.yimg.com/a/i/us/we/52/'+ $(this).attr("code") +'.gif" alt="weather" />');
				$(".temperature_txt.jeru").html($(this).attr("temp") +' &deg;F');
			});
		}
		else { //Tel Aviv
			$(theXmlDoc).find('[nodeName="yweather:condition"]').each(function(){
				$(".temperature_icon.tel").html('<img src="http://l.yimg.com/a/i/us/we/52/'+ $(this).attr("code") +'.gif" alt="weather" />');
				$(".temperature_txt.tel").html($(this).attr("temp") +' &deg;F');
			});
		}
	});
}
