var animate = false;
var months = 3;

function setCalendarHeight()
{
	var h = $(window).height() - $("#leftmenu").height();
	
	if (h < 360)
		months = 1;
	else if (h < 500)
		months = 2;
	else
		months = 3;
		
	$('#calendarwrapper').height(months * 138);
}

$(document).ready(function(){
	
	$('#prevmonth').click(function(){
		if (!animate)
		{
			var t = parseInt($('#calendar').css("top"));
			if (t > (6 - months) * -138)
			{
				animate = true;
				$('#calendar').animate({ 
	        		top: (Math.max(t - 138, (6 - months) * -138)) + "px"
	      		}, 500, null, function(){ animate = false; } );
	      	}
	      }

	});
	
	$('#nextmonth').click(function(){
		if (!animate)
		{
			var t = parseInt($('#calendar').css("top"));
			if (t < 0)
			{
				animate = true;
				$('#calendar').animate({ 
	        		top: (t + 138) + "px"
	      		}, 500, null, function(){ animate = false; } );
	      	}
	      }
	});
	
	$('.tooltip').appendTo('body');

	$('.isEvent').ezpz_tooltip({
		contentPosition: 'belowStatic',
		stayOnContent: true,
		offset: -2
	});

	$(window).resize(function(){
		setCalendarHeight();
	});
	
	setCalendarHeight();
});