$(document).ready(function(){
	$("span.tooltip").hide();
	var tooltips_visible = false;
	
	$(".has-events a").hover( function(event) {
		if (!tooltips_visible) {
			$(this).children("span.tooltip").fadeIn();
			tooltips_visible = true;
		}
	},
	function (event) {
		if (tooltips_visible) {
			$(this).children("span.tooltip").fadeOut("fast", function() { tooltips_visible = false; });
		}
	});
	
	$('#calendar-nav a#prev-month, #calendar-nav a#next-month').click(function(){
		$.ajax({
			async: false
			,type: "POST"
			,dataType: "script"
			,url: config_dir+'ajax/qry_EventsCalendar.js.php'
			,data: 'date='+$(this).attr('href')
			,error: function(XMLHttpRequest, textStatus, errorThrown){
				alert("Unable to request events calendar. Please try again later.");
			}
			//,success: function(msg){
			//	alert(msg);
			//}
		});
		//alert(table_contents);
		if(table_contents)
		{
			$('#calendar_container').fadeOut('fast'
									, function(){
										$(this).html(table_contents).fadeIn('fast')
									});
			$('#prev-month a').attr('href', prev_date);
			$('#next-month a').attr('href', next_date);
		}
		return false;
	});
});
