$(document).ready(function() {
	if ($("#calendario").length)
		setCalendarEvent();
	if ($(".bk_regards").length)
		setRegardsEvent();
});
// Chiusura ed apertura dei blocchi dei saluti
function setRegardsEvent() {
	$(".bk_regards:gt(0) .content").hide();
	$(".bk_regards:eq(0) .title img").hide();
	$(".title img").click(function() {
		$(".bk_regards .content").hide();
		$(".title img").show();
		$(this).hide();
		$(this).parent().parent().find(".content").show();
	});
}
// Apparizione e scomparsa dei fumetti nel calendario
function setCalendarEvent() {
	$(".popup_sx").click(function() {
		numHeight = $(this).height();
		numOffset = $(this).offset();
		balloonTop = numOffset.top - 159 + (numHeight/2);
		balloonLeft = numOffset.left - 218;
		showBalloon("sx", $(this).parent().find(".desc").html(), balloonTop, balloonLeft);
	});
	$(".popup_dx").click(function() {
		$(".balloon_sx").remove();
		$(".balloon_dx").remove();
		numHeight = $(this).height();
		numWidth = $(this).width();
		numOffset = $(this).offset();
		balloonTop = numOffset.top - 159 + (numHeight/2);
		balloonLeft = numOffset.left + numWidth - 31;
		showBalloon("dx", $(this).parent().find(".desc").html(), balloonTop, balloonLeft);
	});
	$(".popup_sx:first").click();
}
function showBalloon(type, content, balloonTop, balloonLeft) {
	$("#balloon").remove();
	$("#BL_footersx").remove();
	$("#BL_footerdx").remove();
	balloon = "<div id='balloon'>";
	balloon += "<div id='BL_top'></div>";
	balloon += "<div id='BL_sx'></div>";
	balloon += "<div id='BL_cen'>";
	balloon += content;
	balloon += "</div>";
	balloon += "<div id='BL_dx'></div>";
	balloon += "</div>";
	balloon += "<div id='BL_footer"+type+"'></div>";
	$("body").append(balloon);
	$("#balloon div:not(div#BL_cen)").ifixpng();
	$("#BL_footer"+type).ifixpng();
	$("#balloon").css({top: balloonTop+"px", left: balloonLeft+"px"});
	$("#BL_footer"+type).css({top: balloonTop+100+"px", left: balloonLeft+"px"});
}