$(document).ready(function()
{
	$("#nav li:last-child").css("border","none");
	$(".quicklinks li:last-child").css("border","none");
	$(".subnav li:last-child").css("border","none");
	//$("body").css("backgroundColor", "#ff0000");	
	
	initCalendar();
});

function initCalendar()
{
	$('a.prev-month').click(function(e){
		e.preventDefault();
		tableDiv = $(this).parents('table').parent();    
		prevMonthCalendar(tableDiv);
	} );
	$('a.next-month').click(function(e){
		e.preventDefault();
		tableDiv = $(this).parents('table').parent();    
		nextMonthCalendar(tableDiv);
	} );
}    
function prevMonthCalendar(tableDiv) {
	month_n = tableDiv.children('div.month_n').html();                                
	year_n = tableDiv.children('div.year_n').html();
	parseInt(month_n) == 1 ? prevMonth = 12 : prevMonth = parseInt(month_n) - 1 ; 
	if (parseInt(month_n) == 1)
			year_n = parseInt(year_n) -1;
	$.get("<?php bloginfo('url'); ?>", {ajaxCalendar: 'true', calmonth: prevMonth, calyear: year_n}, function(data){
		tableDiv.html(data);
		initCalendar();
	});
}
function nextMonthCalendar(tableDiv) {
	month_n = tableDiv.children('div.month_n').html();                                
	year_n = tableDiv.children('div.year_n').html();
	parseInt(month_n) == 12 ? nextMonth = 1 : nextMonth = parseInt(month_n) + 1 ; 
	if (parseInt(month_n) == 12)
			year_n = parseInt(year_n) + 1;
	$.get("<?php bloginfo('url'); ?>", {ajaxCalendar: 'true', calmonth: nextMonth, calyear: year_n}, function(data){
		tableDiv.html(data);
		initCalendar();
	});
}
