$(document).ready(function() {
    function staticNav() {
		var winWidth = $(window).width();
		if ($("#right").height() < $(window).height() && winWidth > 999 && $("#sidebar_content").text() != ""){
			var rightMargin = (winWidth - $("#wrapper").width()) / 2;
			$("#right").css({'position' : 'fixed'});
			$("#right").css({'right' : rightMargin});
        }		
        else{
            $("#right").css({'position' : 'static'});
		}
    }
	function expandContent(){
		var rightfloatHeight = $("#right").height();
		var leftfloatHeight = $("#left").height();		
		if (rightfloatHeight > leftfloatHeight){
			var contentexp = $("#content").height() + rightfloatHeight - leftfloatHeight;
			$("#content").css({'min-height' : contentexp});
		}
	}
	function alignNav(){
		$("#navigation li ul li").css({'min-width' : $("#navigation li").width()});	
	}
	function widthFix(){
		if($(window).width() < 1020){
			$("#navigation li a img").css({'display' : 'none'});
			$("#left").css({'margin-right' : '160px'});
			$("#wrapper").css({'padding' : '0'});
		}
		else{
			$("#navigation li a img").css({'display' : 'inline'});
			$("#left").css({'margin-right' : '170px'});
			$("#wrapper").css({'padding-left' : '5px'});
			$("#wrapper").css({'padding-right' : '5px'});
		}
	}
	widthFix(); //Pfeile in Navigation und #left Breite
    staticNav(); //Right-Float to static	
	alignNav(); //Unterpunkte Breite
	expandContent(); //ContentHeight=RightSidebarHeight
    $(window).resize(function (){ 
        staticNav();
		alignNav();
		widthFix();
    });	
	$("a[rel='extern']").click( function() {window.open($(this).attr('href') );return false;});
	$("a[href$='.pdf']").click( function() {window.open($(this).attr('href') );return false;});
	$(".slideUpParent").click(function(){$(this).parent().slideUp();expandContent();return false;});
	$(".toggleAlert").click(function(){$(this).next().slideToggle();expandContent();return false;});
});