/**
 * @requires jQuery
 */
$.fn.equalizeHeights = function(){
	if(window.top == window.self) {
		return $(this).css('min-height', Math.max.apply(this, $(this).map(function(i,e){ return $(e).outerHeight(); }).get() ) );
	} else {
		return '0';
	}
};

// Do stuff when DOM is ready
$(document).ready(function() {

	// Makes tabbed modules out of modules with more than one module content area inside
	if (typeof NetR.TabbedModule !== "undefined") {
		$('.m').each(function() {
			if($(this).children('.m-c').length > 1) {
				$(this).children('.m-c:first').addClass("active");
				new NetR.TabbedModule($(this));
				if (typeof $.fn.highlightsPager !== "undefined") {
					$(this).find('.m-f').highlightsPager(4000).find('ul').lavaLamp({speed: 300});
				}
			}
		});
	}
	
	$('.cal-nav a').live('click', function() {
		var url = $(this).attr('href').split('#')[0];
		var table = $(this).closest('.event-cal');
		var context = table.parent().attr('id');
		$.ajax({
			url: url,
			success: function(data) {
				table.replaceWith($(data).find('#'+context+' .event-cal'));
			}
		});
		return false;
	});

	/* Enables the tooltips */
	$('.event-cal').each(function(){
		$('a.load-local', this).cluetip({
			cluetipClass: 'frolunda',
			closePosition: 'title',
			closeText: 'Stäng',
			topOffset: 50,
			leftOffset: 20,
			mouseOutClose: true,
			sticky: true,
			local: true,
			arrows: true,
			clickThrough: true,
			showTitle: true,
			cursor: 'pointer',
			hoverIntent: {
				sensitivity: 1,
				interval: 50,
				timeout: 0
			}
		});
	});
	/* Hide the cluetip (see separate plugin) when switching tabs (see separate plugin) */
	$('.tabbed-module li a').click(function() {
		$('#cluetip').hide();
	});
	/* Flicker fix for IE6 */
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch (err) { }
});

$(window).load(function(){
	$('.row').each(function(){
		$(this).find('.col').equalizeHeights();
	});
});
