/**
 * @author michael.gonzalez
 */
$(document).ready(function(){
	$.get('http://img.sports-gambling.com/js/weather/weatherConection.php?yw='+$('#weatherSelector').val(), function(xml){
		var html = '';
		jQuery.each(jQuery.browser, function(i, val) {
			if($.browser.msie){
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async = "false";
                xmlDoc.loadXML(xml);
			}else{
				parser = new DOMParser();
                xmlDoc = parser.parseFromString(xml, "text/xml");
			}
		});
		html = '<h2>' + $(xmlDoc).find('condition').attr('text') + '</h2>';
		html += '<p>Humidity: ' + $(xmlDoc).find('atmosphere').attr('humidity') + '%<br />Visibility: ' + $(xmlDoc).find('atmosphere').attr('visibility')+' mi<br />';
		html += 'Sunrise: ' + $(xmlDoc).find('astronomy').attr('sunrise') + '<br />Sunset: ' + $(xmlDoc).find('astronomy').attr('sunset')+'</p>';
		html += '<div id="weatherImg"><img src="http://img.sports-gambling.com/images/weather/weatherImages/weather/' + $(xmlDoc).find('condition').attr('code') + 'd.png" width="250" height="180" /> <span>' + $(xmlDoc).find('condition').attr('temp')+'&deg;</span>';
		html += '<p>High: '+$(xmlDoc).find('forecast:eq(0)').attr('high')+'&deg;&nbsp;&nbsp; Low: '+$(xmlDoc).find('forecast:eq(0)').attr('low')+'&deg;</p></div>';
        html += '<span id="wTomorrow">Forecast (<i>'+$(xmlDoc).find('forecast:eq(1)').attr('date')+'</i>):<br />'+$(xmlDoc).find('forecast:eq(1)').attr('text')+'<br />';
		html += 'High: '+$(xmlDoc).find('forecast:eq(1)').attr('high')+'&deg;&nbsp;&nbsp; Low: '+$(xmlDoc).find('forecast:eq(1)').attr('low')+'&deg;';
		html += '<img class="wtomorrowimg" src="http://img.sports-gambling.com/images/weather/weatherImages/miniweather/'+$(xmlDoc).find('forecast:eq(1)').attr('code')+'d.png" /></span>';
		$('#wrapperWeather').html(html);
    }, 'xml');
	
	
	$('#weatherSelector').change(function(){
		$.get('media/js/weatherConection.php?yw='+$(this).val(), function(xml){
            var html = '';
			jQuery.each(jQuery.browser, function(i, val) {
				if($.browser.msie){
					xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async = "false";
                    xmlDoc.loadXML(xml);
				}else{
					parser = new DOMParser();
                    xmlDoc = parser.parseFromString(xml, "text/xml");
				}
			});
			html = '<h2>' + $(xmlDoc).find('condition').attr('text') + '</h2>';
			html += '<p>Humidity: ' + $(xmlDoc).find('atmosphere').attr('humidity') + '%<br />Visibility: ' + $(xmlDoc).find('atmosphere').attr('visibility')+' mi<br />';
			html += 'Sunrise: ' + $(xmlDoc).find('astronomy').attr('sunrise') + '<br />Sunset: ' + $(xmlDoc).find('astronomy').attr('sunset')+'</p>';
			html += '<div id="weatherImg"><img src="http://img.sports-gambling.com/images/weather/weatherImages/weather/' + $(xmlDoc).find('condition').attr('code') + 'd.png" width="250" height="180" /> <span>' + $(xmlDoc).find('condition').attr('temp')+'&deg;</span>';
			html += '<p>High: '+$(xmlDoc).find('forecast:eq(0)').attr('high')+'&deg;&nbsp;&nbsp; Low: '+$(xmlDoc).find('forecast:eq(0)').attr('low')+'&deg;</p></div>';
            html += '<span id="wTomorrow">Forecast (<i>'+$(xmlDoc).find('forecast:eq(1)').attr('date')+'</i>):<br />'+$(xmlDoc).find('forecast:eq(1)').attr('text')+'<br />';
			html += 'High: '+$(xmlDoc).find('forecast:eq(1)').attr('high')+'&deg;&nbsp;&nbsp; Low: '+$(xmlDoc).find('forecast:eq(1)').attr('low')+'&deg;';
			html += '<img class="wtomorrowimg" src="http://img.sports-gambling.com/images/weather/weatherImages/miniweather/'+$(xmlDoc).find('forecast:eq(1)').attr('code')+'d.png" /></span>';
			$('#wrapperWeather').flip({
				color:'transparent',
				direction: 'lr',
				onAnimation: function(){$('#wrapperWeather').html(html);}
			});
        }, 'xml');
	});
});
