// Get Omaha's weather from weather.com
function getWeather() {
	$('#wTime').html('');
	$('#location').html('');
	// Scraped Content
	$('#wIcon').load('../include/weather.php .twc-second .twc-animated-icon img',
		function() {
			$('#wIcon img').attr('width', 75).attr('height', 75);
		}
	);
	$('#wTemp').load('../include/weather.php .twc-second .twc-forecast-temperature strong:first',
		function(){
			$('#wTemp').css('font-size', '22px').css('margin', '25px 0 0 5px').css('color', '#000');
			$('#w').after('<div id="location" style="position:absolute; top:58px; width:140px; text-align:center; color: #666; font-weight: normal; font-size: 11px;">Omaha, NE <span id="wTime"></span>\
				</div>').ready(
				function() {
					$('#wTime').load('../include/weather.php .twc-update-refresh h3',
						function(){
							var time = $('#wTime h3').html();
							//alert(time);
							var timeRA = time.match(/\d+:\d{2}?/mi);
							time = timeRA[0]
							
							$('#wTime').html(changeTime(time));
							
							if($('#wTemp').html()!='') {
								$('#loadWeather').fadeOut(); 
							}
							
							$('#weather').fadeIn();
						}
					);
				}
			);
		}
	);
	// Reload weather every 10 minutes
	setTimeout("getWeather();", 600000);
}
	
// Change to 12-hour CDT clock
function changeTime (time) {
	var HM = time.match(/(\d+):(\d{2})/);
	var hour = HM[1]-1;
	var ampm = 'am';
	
	// Change hour to 12-hour clock
	if(hour>=12) {
		hour = hour%12>0?hour%12:12;
		ampm = 'pm';
	}
	var minute = HM[2]
	return(hour+':'+minute+ampm+' CDT');
}

$(document).ready(function(){
	getWeather();
});
