/*************** Time and Weather  ******************************/
function getWeather(){
	myDate=new Date();
	url = 'weather.php?'+myDate.getTime(); 
	new Ajax.Request(url, {   
		method: 'get',   
		onSuccess: function(theresponse) { 
			arr = theresponse.responseText.split('|');
			// update time ??
			if ($('hkWeather')!=undefined) $('hkWeather').innerHTML = arr[1];
		} }); 
	resetTime();
}

var theTimer = null;
var pageStart = true;
function resetTime(){
	checkWeatherMins = 5;
	timeoutSecs = 30;
	
	if (!pageStart)	thess+=timeoutSecs;
	seccount+=timeoutSecs;
	
	
	if (thess >= 60){theii ++;thess = 0;}
	if (theii >= 60){theHH ++;theii = 0;}
	if (theHH == 24){theHH = 0;}
	if (theHH < 12) {
		dapm = ' a.m.';
		dHH = theHH;
	} else {
		dapm = ' p.m.';
		dHH = theHH-12;
	}
	if (dHH == 0) dHH = 12;
	
	if ($('hkTime')!=undefined) {
		tmp = new Date();
		$('hkTime').innerHTML = dHH+":"+theii;
		//$('hkTime').innerHTML += ":"+thess ;
		$('hkTime').innerHTML += dapm ;
		
	}
	if (seccount >= checkWeatherMins*60){
		seccount = 0;
		getWeather();
	}	
	clearTimeout(theTimer);
	if (pageStart) pageStart = false;
	theTimer = setTimeout("resetTime()", timeoutSecs*1000);	
}
