var cppc = cppc || {};
cppc.weather = (function($) {
	var $block, $timeblock;

	var init = function() {
		$block = $('#sidebar div.block-weather').html('<a href="http://news.bbc.co.uk/weather/forecast/2201?&search=milton%20keynes&itemsPerPage=10&region=world&area=Milton%20Keynes"><img src="http://www.campbell-park-youth.org.uk/modules/weather/images/64T/na.png" alt="clear sky" /></a><p>15&ordm;C, Clear Sky<br /><strong>21:30</strong>, Humidity: 72%</p>');
		$timeblock = $block.find('strong');
		setInterval(update_time, 60000);
		
		$block.bind('click', function() {
			window.location.href = $(this).find('a:first').attr('href');
		});
	}
	
	var update_time = function() {
		var time = $timeblock.text();
		var timearr = time.split(':');
		timearr[0] = parseInt(timearr[0], 10);
		timearr[1] = parseInt(timearr[1], 10);
		if (++timearr[1]>59) {
			timearr[1]=0;
			if (++timearr[0] == 24) {
				timearr[0] = 0;
			}
		}
		if (timearr[0] < 10) timearr[0] = '0'+timearr[0];
		if (timearr[1] < 10) timearr[1] = '0'+timearr[1];
		$timeblock.text(timearr.join(':'));
	}

	return {
		init : init
	}
})(jQuery);

jQuery(cppc.weather.init);