// JavaScript Document

/*-------------------------------------------------------
----------------- Calendar Stuff ------------------------
-------------------------------------------------------*/

//this function will be called on page load and will do the inital load of the calendar and the prev and next buttons
function pageLoad()
{	
	//set the loading div to show
	$("#calLoad").show();
	
	//set the click events on the arrows
	$("#calPrevDiv").click(function(){ changeMonth("prev"); });
	$("#calNextDiv").click(function(){ changeMonth("next"); });
	
	//set up the current month
	var currMonth = $("#currMonth").html();
	var currYear = $("#currYear").html();
	loadNewCal(currMonth, currYear);
}

//this function will be called when the month needs to be changed
function changeMonth(monthDirection)
{
	//set the loading div to show and the calender div to hide
	$("#calLoad").show();
	$("#calContent").hide();
	
	//change the divs with the month and year to update to the new month and year
	var currMonth = $("#currMonth").html();
	var currYear = $("#currYear").html();
	
	if (monthDirection == 'prev')
	{
		currMonth--;
	} else
	{
		currMonth++;
	}
	
	if (currMonth == 0)
	{
		currYear--;
		currMonth = 12;
	} else if (currMonth == 13)
	{
		currYear++;
		currMonth = 1;
	}
	
	$("#currMonth").html(currMonth);
	$("#currYear").html(currYear);
	
	$("#calMonthDiv").html(getMonthName(currMonth) + " " + currYear);
	
	loadNewCal(currMonth, currYear);
}

//this function call a php page to set up the new calendar
function loadNewCal(loadMonth, loadYear)
{
	$("#tempCalContent")
		.stop()
		.load("jsIncludes/calendarBuild.php", { loadMonth:loadMonth, loadYear:loadYear }, function(){ showNewCal($("#tempCalContent").html()); });
}

//this function will display the new calendar
function showNewCal(newCal)
{
	$("#calContent")
		.html(newCal)
		.show();
	setUpEvents();
	$("#calLoad").hide();
}