jQuery(function($) {
	bind();
});

function showCalendar(year,month,cat,homecal)
{
	var params = {
		y: year,
		m: month,
		category: cat,
		homepage: homecal
	};
	//console.log(params);
	$('#calendar').hide();
	$('#calendar').load('../php/ajax-calendar.php',params,bind);
	$('#calendar').fadeIn('slow');
	
	
}

function bind()
{
	//alert('bind');
	//#show previous and next links and filter dropdown - functionality only available for those with js 
	$('#calendar li.previous a, #calendar li.next a, #calendar #category').show();
	//#when category highlight filter changed, adjust calendar highlighting
	$('#formFilter #category').change( function (){ 
		showCalendar($('#year').val(),$('#month').val(),$(this).val(),$('#homepage').val()); 
	});	
	//#when home category view dropdown changed, submit the form so that user will be brought to category page 
	$('#formNav #category').change( function (){ 
		if($(this).val() != '')
		{
			$(this).parent('form').submit();
		}
	});	
}