$(document).ready(function(){
	function setWorldTime( obj ) {
		var d 	= new Date();
		minutes = d.getUTCMinutes();
		hours 	= d.getUTCHours()+8;
		
		d = new Date();

		// convert to msec
		// add local time zone offset 
		// get UTC time in msec
		utc = d.getTime() + (d.getTimezoneOffset() * 60000);
		
		if( minutes < 10 )
			minutes = "0"+minutes;
		
		for( var i=0; i<obj.length; i++ ){
			// create new Date object for different city
			// using supplied offset
			nd = new Date( utc + (3600000*obj[i].diff) );
			nh = nd.getHours();
			nm = nd.getMinutes();
			
			nh = formatTime( nh );
			nm = formatTime( nm );
			
			$("#"+obj[i].id).html( nh + ":" + nm + "hrs" );
		}
	};
	
	function formatTime( num ){
		if( num < 10 )
			num = "0"+num;
			
		return num;
	}
	setWorldTime( Global_Times.data );
});

function parseEntries(feed_url, callback){
	requestURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=ummWu3Fl3hGFgLVz0z6skA&_render=json&_callback=?&url=" + feed_url;
    $.getJSON(requestURL, function(json, status){
		callback(json.value.items, status);
	});
}

function parseWeatherFeed( lat, lng ){
	var feed_url = "feed%3A%2F%2Fapi.wxbug.net%2FgetLiveWeatherRSS.aspx%3FACode%3DA5676680785%26lat%3D"+lat+"%26long%3D"+lng+"%26unittype%3D1";
	parseEntries(feed_url, function(json, status){
	var content = "";
	$.each(json, function(i){
		strContent = "";
		var arrContentSplit = this['description'].split("<b>");
		arrContentSplit = arrContentSplit.slice( 1 );
		
		var arrContent = new Array();
		arrContent.push( arrContentSplit[0] );
		arrContent.push( arrContentSplit[1] );
		arrContent.push( arrContentSplit[3] );
		arrContent.push( arrContentSplit[7] );
		
		for( var i=0; i<arrContent.length; i++ ){
			arrContent[i] = arrContent[i].replace("<br />", " ");
			arrContent[i] = arrContent[i].replace("</b>", "</strong>");
			arrContent[i] = "<li><strong>"+arrContent[i]+ "</li>";
			
			strContent +=  arrContent[i];
		}
		      
	});
	 $("#weather-feed").append(strContent);
	});
}
