var timeout_chiudi_calendario = 0;

$(function() {
	
	$(".calendario").bind('refresh', function() {
		$('.calendario').each(function() {
			var questo = $(this);
			var from = $(this).attr("mese");
			$.get('/event/ajax/calendario/from,' + from, { from: from }, function(data) {
				questo.html(data);
			})
		});
	});
	
	$(".calendario").trigger('refresh');
});

$(".calendario-cambio-mese").live("click", function() {
	
	$(this).parent().attr('mese', $(this).attr("mese"));
	
	$('.calendario').trigger('refresh');
	
});

$(".event-active").live('mouseover', function(e) {
	
	var eId = $(this).attr("eId");
	var messaggio = $(this).attr("title");
	var link = $(this).attr("link");
	var posizione = $(this).position();
	var corpo = $(this).parent().parent().parent().parent();
	
	$(".tooltip-evento", corpo)
		.html('')
		.fadeIn()
		.css({
			position: 'absolute',
			left: 10 + posizione.left + 'px',
			top: posizione.top - 50 + 'px',
			width: 200,
			zIndex: 999,
			color: 'white',
			fontFamily: 'Light'
		});
	
	$('<div />')
		.html('<p style="background-color: #8B8B8B; padding: 10px; margin: 0px"><a style="color: white" href="/article/'+link+'">'+messaggio+'</a></p>')
		.append('<img style="float: left" src="/views/east/images/etichette/tooltip.png" />')
		.appendTo(".tooltip-evento");
	
	clearTimeout(timeout_chiudi_calendario);
	
});

$(".tooltip-evento").live("mouseover", function() {
	clearTimeout(timeout_chiudi_calendario);
	
	$(".tooltip-evento").one("mouseout", function() {
		timeout_chiudi_calendario = setTimeout('closeTooltip()', 500);
	});	
});

$(".event-active").live('mouseout', function() {
	timeout_chiudi_calendario = setTimeout('closeTooltip()', 500);
})

function closeTooltip() {
	$(".tooltip-evento").fadeOut();
}
