$(window).load(function(){
	for (var i = 1; i < 3; i ++)
	{
		var maxHeight = 0;
		$('.maxheight' + i).each(function(){ maxHeight = Math.max(maxHeight, $(this).height()); });
		$('.maxheight' + i).height(maxHeight);
	}
});
$(document).ready(function(){
	if (typeof(Prototype) != "undefined")
		return;
	// Don't try to perform column-size-matching on older versions of ie
	if ($.browser.msie == true && Number($.browser.version) > 7)
		$(".widget:not(.straightedged), .widget:not(.straightedged) .inner, .filler:not(.straightedged), #breadcrumb").corner("5px");


	$('.widget-row').each(function(){
		var maxHeight = 0;
		$(this).children('.widget').each(function(){ if ($(this).height() > maxHeight){ maxHeight = $(this).height(); } });
		$(this).children('.widget').css({ height: maxHeight })
	});

	$('#content-left .widget:last').addClass('last');
	$('#content-right .widget:last').addClass('last');

	if ($('#content-right .widget').length == 0 && $('#content-right .small-calendar').length == 0)
		$('#content-right').hide();

	$('.linkwidget').each(function(i){
		var link = $('#widget'+ (i+1) +'_link a:eq(0)');
		if (link.length)
		{
			$(this).addClass('hasLink');
			$(this).click(function(){ document.location.href = link.attr('href'); });
		}
	});

	var lastclickdate = null;
	$('.small-calendar .day.hilight').addClass('hasLink').click(function(){
		var clickdate = $(this).children('span').html();
		var popup = $('.popup');
		if (lastclickdate == clickdate && popup.css('display') == 'block')
			popup.hide();
		else
		{
			$('.event').css('display', 'block'); // to refresh all the events
			$('.event[rel!="' + clickdate + '"]').css('display', 'none'); // to hide all events that don't correspond to the clicked day        
			popup.css('width', '268px').show();
			var e = $(this);
			var y = e.position().top + e.height() + 20;
			var x = e.position().left + (e.width() / 2);
			x = Math.floor(x - 160); // based on the placement on the arrow on the popup div (not centered)
			$('.popup').css({'top': y + 'px', 'left': x + 'px' });
		}
		lastclickdate = clickdate;
	});
	$('.popup-close').click(function() {
		$('.popup').hide();
	});
});

