// JavaScript Document

$(document).ready(function(){
	// Teaser anpassen
	var myTeasers = $(".teaserContainer .teaser");
	var teaserLeft = new Array();
	var teaserRight = new Array();
	
	// Step 1: Alle Teaser nach Inhalt aufspannen - minHeight: 180;
	myTeasers.each(function(index) {
		// Text
		var theContent = $(this).find("p");
		theContent.css("height","auto");
	    var aktHeight = theContent.height();
		var minHeight = 180;
		var newHeight = 180 + (aktHeight - (115 - $(this).find("h3").height()));			
		if (newHeight > minHeight) {		
			$(this).height(newHeight);
		}
		
		// Teaser nach links/rechts verteilen
		if ((index+1)%2 == 0) {
			teaserRight.push($(this));	
			$(this).after("<div class='clear'></div>");
		} else {
			teaserLeft.push($(this));		
		}
	});
	
	// Step 2: Teaser in einer Reihe gleich hoch machen
	for (var i=0;i<teaserLeft.length;++i) {
		if (teaserLeft[i] && teaserRight[i]){
			
			// Headline
			var headlineLeft = teaserLeft[i].find("h3");
			var headlineRight = teaserRight[i].find("h3");
			if (headlineLeft.height() > headlineRight.height()) {
				headlineRight.height(headlineLeft.height());
				teaserRight[i].height(teaserRight[i].height()+15);				
			} else  if (headlineLeft.height() < headlineRight.height()) {
				headlineLeft.height(headlineRight.height());
				teaserLeft[i].height(teaserLeft[i].height()+15);				
			}
			
			// Content
			if (teaserLeft[i].height() > teaserRight[i].height()) {
				teaserRight[i].height(teaserLeft[i].height());
			} else if (teaserLeft[i].height() < teaserRight[i].height()) {
				teaserLeft[i].height(teaserRight[i].height());
			}
			
			
		}
	}						   
});
