AllowHide=false;

function HideMenu()
{
	if (AllowHide) $("#main-menu").hide();
}

function isCalendarTabHere(Year)
{
	return $("#d-calendar-year-"+Year).html()!=null;
}

function changeTab(New, Previous)
{
	$("#d-calendar-year-"+New).show();
	$("#d-calendar-year-"+Previous).hide();
}

function hideArrows(Year)
{
	if (!isCalendarTabHere(Year-1)) $("#d-calendar-y-down").hide(); else $("#d-calendar-y-down").show();
	if (!isCalendarTabHere(Year+1)) $("#d-calendar-y-up").hide(); else $("#d-calendar-y-up").show();
}

$(function()
{
	$(".d-menu").mouseenter(function()
	{
		AllowHide=false;
		
		Id=$(this).attr("id").split("-")[2];
		Offset=$(this).offset();
		
		if ($("#menu-content-"+Id).html()==null)
		{
			$("#main-menu").fadeOut(100);
			return;
		}
		
		$("#main-menu .content").html($("#menu-content-"+Id).html());
		$("#main-menu").css("left", Offset.left);
		$("#main-menu").css("top", Offset.top+35);
		
		$("#main-menu").fadeIn(100);
		w=$("#menu-content-"+Id).outerWidth()-20;

		$("#main-menu").find("li").each(function()
		{
			$(this).css("width", w);
		});
		
		$("#main-menu .shadow-right").css("width", w+10);
		$("#main-menu .clear").css("width", w);
		$("#main-menu .shadow-down").css("width", w-10);
		
	});
	
	$("#main-menu").mouseenter(function()
	{
		AllowHide=false;
	});
	
	$("#letters .right a, #main-menu, #menu").mouseleave(function()
	{
		AllowHide=true;
		setTimeout("HideMenu();", 30);
	});

	$("#letters .right a").mouseenter(function()
	{
		AllowHide=false;

		Id=$(this).attr("id").split("-")[1];
		Offset=$(this).offset();

		$("#main-menu .content").html($("#letters-content-"+Id).html());
		$("#main-menu").css("left", Offset.left);
		$("#main-menu").css("top", Offset.top+35);

		$("#main-menu").fadeIn();
		w=$("#letters-content-"+Id).outerWidth()-20;
		if (w>200) w=200;

		$("#main-menu").find("li").each(function()
		{
			$(this).css("width", w);
		});

		$("#main-menu .shadow-right").css("width", w+10);
		$("#main-menu .clear").css("width", w);
		$("#main-menu .shadow-down").css("width", w-10);

	});
	
	$(".show-calendar").click(function()
	{
		Offset=$("#content .right .calendar").offset();
		$("#calendar").css("left", Offset.left-17);
		$("#calendar").css("top", Offset.top-13);
		$("#calendar").fadeIn(150);
		return false;
	});
	
	$(".hide-calendar").click(function()
	{
		$("#calendar").fadeOut(150);
		return false;
	});
	
	$("#d-calendar-y-down").click(function()
	{
		Year=$("#d-calendar-y").html();
		
		if (isCalendarTabHere(parseInt(Year)-1))
		{
			Year--;
			changeTab(Year, Year+1);
			$("#d-calendar-y").html(Year);
			hideArrows(Year);
		}
		return false;
	});
	
	$("#d-calendar-y-up").click(function()
	{
		Year=$("#d-calendar-y").html();

		if (isCalendarTabHere(parseInt(Year)+1))
		{
			Year++;
			changeTab(Year, Year-1);
			$("#d-calendar-y").html(Year);
			hideArrows(Year);
		}

		return false;
	});	
	
	$(".lightbox").lightBox();
	
	$("#get-pet").microModal({autoPositioning: true, overlay: {show: true,color:'#000',opacity: 0.03} });
	$("#get-pet-icon").click(function(){
		$("#get-pet").click();
		return false;
	});
	$("#guestBook").microModal({autoPositioning: true, overlay: {show: true,color:'#000',opacity: 0.03} });
	$("#guestBook-icon").click(function(){
		$("#guestBook").click();
		return false;
	});
	
	$(".fly-w").hover(function(){$(this).find(".fly").removeClass("hidden");}, function(){$(this).find(".fly").addClass("hidden");});
});

function PetFormClose()
{
	$.fn.microModal.dialogs['#getPetForm'].close();
}

function GuestbookFormClose()
{
	$.fn.microModal.dialogs['#guestBookPost'].close();
}
