/**
 * @author bastianw
 */

function setSortimentnavHeight(height) {
		if (height > 500) {
			$('div.sortimentsfinder div.fallback').height(height);
			$('div.sortimentsfinder div.contentOuter').height(height);
			$('div.sortimentsfinder div.contentOuter embed').height(height);
			$('div.sortimentsfinder div.contentOuter object').height(height);
			$('div.sortimentsfinder div.navigation').height(height);
			$('div.sortimentsfinder div.label').height(height+10);
		}
	}


$(document).ready(function(){
	
	function setSortimentnavHeight(height) {
		if (height > 500) {
			$('div.sortimentsfinder div.fallback').height(height);
			$('div.sortimentsfinder div.contentOuter').height(height);
			$('div.sortimentsfinder div.contentOuter embed').height(height);
			$('div.sortimentsfinder div.contentOuter object').height(height);
			$('div.sortimentsfinder div.navigation').height(height);
			$('div.sortimentsfinder div.label').height(height+10);
		}
	}
	
	
	if($('div.sortimentsfinder').length > 0 ) {
		var navHeight	=	 25;
		$('div.sortimentsfinder div.navigation li').each(function(i,obj){
			navHeight = navHeight + $(this).height();
		});
		
		$('div.sortimentsfinder div#sortiment-crosslinks a').each(function(i,obj){
			navHeight = navHeight + $(this).height();
		});		
		var contentHeight = $('div.sortimentsfinder div.contentInner').height();
			contentHeight = contentHeight + 50;
			
		if (contentHeight > navHeight) {
			setSortimentnavHeight(contentHeight);
		} else {
			setSortimentnavHeight(navHeight);
		}
		

		if ($('div.fallback').length > 0) {
			var items = $('div.fallback .item_small').size();
			var downloadbox	= $('div.fallback .filebox').size();
			var verkaufstellen	= $('div.fallback .verkaufsstellen').size();
			if(items > 0) {
				var rows = Math.ceil(items / 3);
				var height = (rows * $('div.fallback .item_small').height()) + (rows *5) + 20;
				if (height > navHeight) {
					setSortimentnavHeight(height);
				}
			} else if ($('div.fallback .item_big').size() > 0) {
				var height = $('div.fallback .item_big').height();
				if(downloadbox > 0) { height = height + $('div.fallback .filebox').height() +10; }
				if(verkaufstellen > 0) { height = height + $('div.fallback .verkaufsstellen').height() +15;	}
				if (height > navHeight) {
					setSortimentnavHeight(height);
				}
			}
		}
	}
});


