$j=jQuery.noConflict();   


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

function initCalendar() {
	$j('a.prev-month').click(function(e){
		e.preventDefault();
		tableDiv = $j(this).parents('table').parent();    
		prevMonthCalendar(tableDiv);
	} );
	$j('a.next-month').click(function(e){
		e.preventDefault();
		tableDiv = $j(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;
	$j.get("http://08eins.pascalsworld.ch", {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;
	$j.get("http://08eins.pascalsworld.ch", {ajaxCalendar: 'true', calmonth: nextMonth, calyear: year_n}, function(data){
		tableDiv.html(data);
		initCalendar();
	});
}

// function reloadCalendar(e) {
// 	// e.preventDefault();
//  	console.log($j(this).parents('table'));
//     $j.get("http://08eins.pascalsworld.ch", {ajax: 'true'}, function(data){
// 		tableDiv = table.parent();
// 		tableDiv.html(data);
//             });
// }
// 