$(document).ready(function() {	

	// swap plain text for drop-down selector
	//alert("/?action=monthselector&d="+dDate);
	$.ajax({ type: "GET", url: "/events/?action=monthselector&d="+dDate, dataType: "html", success: function(html) {	
			// attach an onchange function to the month to view selector...
			$("#calendar_month_selector").html(html);
			$("#month").change(function() { loadCalendar(this.value);});	
			
			// replace dynamic previous / next links with javascript (ajax) function calls...
			$("#prevMonth").attr("href", "javascript:changeMonth('previous');");
			$("#nextMonth").attr("href", "javascript:changeMonth('next');");
			//calendarEffects();
		} 
	});
});


function loadCalendar(dDate) 	{
	// Function reloads the calendar via AJAX call...
	//$("#calendar_cover").removeClass("hidden");
	$.ajax({ type: "GET", url: "/events/?action=calendar&d="+dDate, dataType: "html", success: function(html) { 
		$("#calendar_holder").html(html);
		//$("#calendar_cover").addClass("hidden");
		//calendarEffects();
	} });
}


function changeMonth(sDirection) {
	// move up and down the month to view selector...
	var dd = document.getElementById("month");
	var i = dd.selectedIndex;		
	switch(sDirection) {
		case "previous": dd.selectedIndex = (i == 0) ? i : (i-1); break;
		case "next": dd.selectedIndex = (i==dd.length-1) ? i : (i+1); break;
	}	
	loadCalendar(dd.value);
}