function displayCal(file) {
	$('div#calwrap table.calendar').remove();
	// load this calendar
	$('div#calwrap').load(file,'',function() {
		// hook all the clicks.
		// hook the anchors for the date infos
		$('div#calwrap table.calendar caption span a').click(function() {
			displayCal($(this).attr('href'));
			return false;
		});
		$('div#calwrap table.calendar tr td a').click(function(e) {
			$('div#dateinfo').remove();
			var href = $(this).attr('href');
			$('div#datewrap').load(href,'',function() {
				$('div#dateinfo').css('top',e.pageY);
				$('div#dateinfo').css('left',e.pageX+20);
				$('div#dateinfo').click(function() {
					$('div#dateinfo').remove();
				});
				return false;
			});
			return false;
		});
		$('body').click(function() {
			$('div#dateinfo').remove();
		});
	});
};


$(function()  {
	
	// Replace the #calwrap 
	var curDate = new Date();
	datefield = curDate.getFullYear().toString();
	monthfield = curDate.getMonth()+1;
	monthfield = monthfield.toString();
	if (monthfield.length < 2) { monthfield = 0 + monthfield; };
	datefield = datefield + monthfield + ".html";
	displayCal('calendar/'+datefield);
/*	$('body').click(function() {
			$('div#dateinfo').remove();
	});
	$('div#calwrap table.calendar tr td a').click(function(e) {
			$('div#dateinfo').remove();
			var href = $(this).attr('href');
			console.log($(this).attr('href'));
			$('div#datewrap').load(href,'',function() {
				$('div#dateinfo').css('top',e.pageY);
				$('div#dateinfo').css('left',e.pageX+20);
				$('div#dateinfo').click(function() {
					$('div#dateinfo').remove();
				});
				return false;
			});
			return false;
	});*/
});

