function prepareCal() { 
	
	var clickNavigation = function(e) {
		e.preventDefault();
		options = {
			url: $(this).attr("href"),
			type: "POST",
			beforeSend: function() {
				$('\#live_calendar div.head a').unbind('click')
				.bind("click.tempo", function(e){ e.preventDefault(); });
				
				_showCalendarLoadingIndicator();
			},
			success: function(data, msg) {
				data = $(data);
				ncal = data.find("div.calendar.container");
				$('div.calendar.container').replaceWith(ncal);
				$('table')
				.show('slide',{ direction: (data.find("span.relative").text() == "next" ? "right" : "left") }, 300); 
				
				_hideCalendarLoadingIndicator();
				prepareCal();
			}
		}
		$.ajax(options);
	};
	
	$("div.calendar")
	.find("table a")
		.mousemove(function() {
			$("div.summary").not("#summary_"+$(this).text()).hide();
			$("#summary_" + $(this).text() )
			.not(":visible")
			.css({position: "relative", top: "20px"})
			.animate({opacity: "show", top: "0px"}, 300);
		})
	.end()
	.find("div.head a")
	.each(function() { $(this).attr("href", $(this).attr("rel")).attr("rel", "") })
	.bind('click', clickNavigation)
	.filterIE6only().hide().end()
}

function _showCalendarLoadingIndicator() {
	cal = $('#live_calendar table');
	l = cal.position().left + (cal.innerWidth() / 2) - 13;
	t = cal.position().top + (cal.innerHeight() / 2) - 13;
	$('<img src="/images/icons/loading.gif" class="cal loading" />').appendTo("body")
	.css({position: "absolute", top: t, left: l, opacity: "0", border: "1px solid #888", padding: "5px", backgroundColor: "white"}).fadeTo("0.5", 100);
}
function _hideCalendarLoadingIndicator() { $(".cal.loading").remove(); }


$(document).ready( prepareCal ); 
