//Initialize the HTTP cache
var remoteCache = new Array();

var remoteUrl = '../inc/calendar_backend.php';
var remoteMonthUrl = '../inc/calendar_backend_month.php';
	
// Initialize calendar after it's been created.
function initCalendar() {

	
	
	//For each day in the calendar...
	$('table.calendar a.calday').each(function(i,item){
		
		//Unique ID for the link
		var linkId = item.id;
		
		//Unique URL for the link
		var linkUrl = remoteUrl+'?timestamp='+linkId;
		
		//Attach onclick event handler
		$(this).click(function(){
			var calendarEvents = $('#calendar-events');			
			calendarEvents.slideUp('fast',function(){
				if( remoteCache[linkId] != undefined ) { 
					calendarEvents.html(remoteCache[linkId]);
					calendarEvents.slideDown('fast');
				} else {
					calendarEvents.load(linkUrl,function(){
						remoteCache[linkId] = calendarEvents.html();
						calendarEvents.slideDown('fast');
					});
				}
			});
			return false;
		});
		
	});







}






	// Month name link
	function showMonthEvents(month, year) {
		
		//Unique URL for the link
		var linkUrl = remoteMonthUrl+'?month=' + month + '&year=' + year;

		var calendarEvents = $('#calendar-events');	
		calendarEvents.slideUp('fast',function(){
					
			calendarEvents.load(linkUrl,function(){
				calendarEvents.slideDown('fast');
			});
			
		   /*
			if( remoteCache[month] != undefined ) { 
				alert('not cached');
				calendarEvents.html(remoteCache[month]);
				calendarEvents.slideDown('fast');
			} else {
				alert('cached rem=' + remoteCache);
				calendarEvents.load(linkUrl,function(){
					remoteCache[month] = calendarEvents.html();
					calendarEvents.slideDown('fast');
				});
			}
			*/
			
		});


	}




jQuery(document).ready(function($){
	initCalendar();	
});
