jQuery(document).ready(function($){
	var h, w, off, i;
	$(".colorful_calendar_day_moreinfo").show().css({ width: 0, height: 0, opacity: 0 });
	
	i = 0;
	$(".colorful_calendar_day_moreinfo").each(function(){
		$(this).css('position', 'absolute');
		$(this).addClass("colorful_calendar_day_" + ++i);
		$(this).closest(".colorful_calendar_cell").find(".colorful_calendar_day_link").attr("calendar_day", i);
		$(this).appendTo("body");
	});
	
	$(".colorful_calendar_day_moreinfo").each(function(){
		var v_top, v_left, _this;
		_this = $(this);
		$(this).wrapInner("<div class='colorful_calendar_day_moreinfo_relative'></div>");
		$("<span class='colorful_calendar_day_moreinfo_otriangle'></span><span class='colorful_calendar_day_moreinfo_itriangle'></span>").appendTo( $(this).find(".colorful_calendar_day_moreinfo_relative") );
		
		/* Outer triangle */
		v_top = _this.css("borderTopWidth").replace(/[^0-9]/g, '')*-1 - _this.find(".colorful_calendar_day_moreinfo_otriangle").css("borderBottomWidth").replace(/[^0-9]/g, '');
		v_left = _this.css("borderLeftWidth").replace(/[^0-9]/g, '')*1 - _this.css("paddingLeft").replace(/[^0-9]/g, '')*1;
		
		$(this).find(".colorful_calendar_day_moreinfo_otriangle").css({ 
			top: v_top,
			left: v_left
		});
		
		/* Inner triangle */
		v_top = _this.css("borderTopWidth").replace(/[^0-9]/g, '')*-1 - 1;
		v_left += _this.find(".colorful_calendar_day_moreinfo_itriangle").css("borderLeftWidth").replace(/[^0-9]/g, '')*1 - 1;
		
		$(this).find(".colorful_calendar_day_moreinfo_itriangle").css({ 
			top: v_top,
			left: v_left
		});
	});
	
	$(".colorful_calendar_day_link").live("mouseover mouseout", function(event){
		var cell = $(this).closest(".colorful_calendar_cell");
		var moreinfo = $(".colorful_calendar_day_" + $(this).attr("calendar_day"));
		if(event.type=='mouseover'){
			off = cell.offset();
			moreinfo.css({ top: off.top + cell.height(), left: (off.left - moreinfo.css('borderLeftWidth').replace(/[^0-9]/g, '')) });
			h = moreinfo.css({ height: 'auto' }).height();
			w = moreinfo.css({ width: 'auto' }).width();
			moreinfo.filter(':not(:animated)').show().animate({ height: h, opacity: 1, width: w }, 200);
		} else {
			moreinfo.animate({ opacity: 0, width: w*.5, height: h*.1 }, 300, function(){ $(this).hide(); });
		}
	});
});
