﻿(function($) {
	//jQuery plugin
	//sets an equal height of a floating collection of elements per line
	$.fn.syncHeightPerLine = function(syncList) {
		syncList = syncList ? $(syncList) : $(this);
		var toSync = [];
		syncList.each(function(i, val) {
			toSync.push(this);
			if (($(this).next().length && $(this).position().top != $(this).next().position().top) ||
				!$(this).next().length
				) {
				$(toSync).height($(toSync).maxHeight());
				toSync = [];
			}
		});
	}

	//jQuery plugin
	//computes the maximal height of an array of elements
	$.fn.maxHeight = function() {
		var max = 0;
		$(this).each(function() {
			var height = $(this).height();
			max = height > max ? height : max;
		});
		return max;
	}
})(jQuery);

function syncTeaserList()
{
    if(jQuery.browser.safari && document.readyState != "complete")
    {
        setTimeout( arguments.callee, 100 );              
        return;
    }
    $(".teaser-list").each(function() {		    
	    $(this).children("ul").children().syncHeightPerLine();
	});  	
}

$(document).ready(function(){
	//sync teaser-lists line height
	syncTeaserList();	
});
