$(document).ready(function() {

	fix_calendar_months();

	$("table.form_table tr").find("td:first").addClass("desccell");

	$("#headerMenu > ul.nav > li > ul").addClass("sub_navigation_class");

	do_dropdowns();

});

function update_calendar(obj) {

	var url = $(obj).attr("href");

	$.post("/ajax/calendar/" + url.substr(url.length - 7, 7),
	{},
	function(data) {
	
		$("#calendar").replaceWith(data);
		
		fix_calendar_months();		
	
	});

}

function fix_calendar_months() {

	// Replace next / forward links in calendar with ajax calls
	if($("#calendar").length) {
		
		$("#calendar th > a:first").click(function(event) {
			event.preventDefault();
			update_calendar(this);
		});
	
		$("#calendar th > a:last").click(function(event) {
			event.preventDefault();
			update_calendar(this);
		});
	}

}

function do_dropdowns() {

	$("#headerMenu > ul.nav li").each(function() {	
	
		$(this).hover(
			function() {
				$(this).children().show();
			},		
			function() {
				$(this).children().not("a").hide();
			}	
		);	
	});

}
