// JavaScript Document

function doubleDigit(val) {
	var result=""+val;
	while (result.length<2) {
		result="0"+result;
	}
	return result;
}

function showTime() {
	var now=new Date();
	var h=(now.getUTCHours()+14)%24;
	var ampm="am";
	if (h>12) {
		ampm="pm";
		h=h-12;
	}
	if (h==0) {
		h=12;
	}
	var m=doubleDigit(now.getUTCMinutes());
	
	document.getElementById('mapTime').innerHTML=h+':'+m+'<span id="mapTimeAMPM">'+ampm+'</span>';
}

function initTime() {
	setInterval(showTime, 1000);
}

function buildWeatherUrl() {
	var now=new Date();
	var timestamp=now.getUTCFullYear()+"-"+doubleDigit(now.getUTCMonth()+1)+"-"+doubleDigit(now.getUTCDate())+"T"+doubleDigit(now.getUTCHours())+":"+doubleDigit(now.getUTCMinutes())+":"+now.getUTCSeconds();
	return "http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?lat=21.309&lon=-158.032&product=time-series&begin="+timestamp+"&end="+timestamp+"&temp=temp&appt=appt"
}

function requestWeather() {
	var url=buildWeatherUrl();
	jQuery.ajax({
		dataType: "xml",
		url: url,
		success: function(data) {
			console.debug(data);
		}
	});
}

function initWeather() {
	requestWeather();
	setInterval(requestWeather, 36000000);
}

jQuery(document).ready(function() {
	initTime();
	//initWeather();
});
