$(document).ready(function()
{
	var isDetailOpened = false;
	var isCloseClicked = false;
	
	$("#CalendarButtons #Prev").click(function()
	{
		var value = $("#BlockCalendar #month").val();
		$("#BlockCalendar #month").val(--value);
		
		$.getJSON("modules/Events/ajax.php?month=" + value,
				  function(data)
				  {
						$("#BlockCalendar h3").html(data.month + " " + data.year);
						$("#BlockCalendar #Calendar").html(data.content);
				  });
	});
	
	$("#CalendarButtons #Next").click(function()
	{
		var value = $("#month").val();
		$("#month").val(++value);
		
		$.getJSON("modules/Events/ajax.php?month=" + value,
				  function(data)
				  {
						$("#BlockCalendar h3").html(data.month + " " + data.year);
						$("#BlockCalendar #Calendar").html(data.content);
				  });
	});
	
	
	$("#Calendar .EventClose").live("click", function()
	{
		$(this).parent().parent().css("position", "relative");
		$(this).parent().hide(100);
		isCloseClicked = true;
	});
	
	$("#Calendar .HasEvent").live("click", function()
	{
		if (!isDetailOpened)
		{
			$(this).css("position", "static");
			$(this).children(".EventDetails").show(100);
			$(this).children(".EventToolTip").hide();
			isDetailOpened = true;
		}
		else
		{
			if (isCloseClicked)
			{
				isDetailOpened = false;
				isCloseClicked = false;
			}
		}
	});
	
	$("#Calendar .HasEvent").live("mouseover", function()
	{
		$(this).children(".EventToolTip").show();
	});
	
	$("#Calendar .HasEvent").live("mouseout", function()
	{
		$(this).children(".EventToolTip").hide();
	});
});