$(document).ready(function(){
	
	// Navigations-Funktion wird geladen
	navigation();
	
	// ServiceIcons
	$('#serviceIcons img').mouseover(function(event){
		changeServiceIcons(event.target.id);
	});	
	
	$('#serviceIcons img').mouseout(function(event){
		changeServiceIcons(event.target.id);
	});		
	
	
	// Sprachwechsler
	$('#langSpan').mouseover(function(event){
		languageChange(0);
	});
	
	$('#header').mouseout(function(event){
		languageChange(1);
	});
	
	$('#langHide').mouseout(function(event){
		languageChange(1);
	});	
	
	$('.feloginSubmit').click(function(event) {
		checkLogin();		
	});
	
	/* Quartalscenter-related */
	$('.thirdLevelNav_qc').click(function(event) {
		var ahref = $(this).children(':first-child').attr("href");
		location.href = ahref;
	});
	
	$('.thirdLevelNavA_qc').click(function(event) {
		var ahref = $(this).children(':first-child').attr("href");
		location.href = ahref;
	});
	
	/*
	$('.mwfcal').hover(
		function () { $(this).css("backgroundColor","#d7d8da"); },
		function () { $(this).css("backgroundColor",""); }
	);
	*/
	
	correct_sizes();
});

function correct_sizes() {
	if($("#nav3wrapper").length != 0) {
		if($("#nav3wrapper").html().length == 0) { $("#middle2").css("width","100%"); }
	}
	else { $("#middle2").css("width","100%"); }
	if($("#n3wrap").length != 0) {
		if($("#n3wrap").height() > $("#c_inner").height()) {
			//$("#middle2").css("height",$("#n3wrap").height()+"px");
		}
		else if($("#c_inner").height() > $("#n3wrap").height()) {
			//$("#middle2").css("height",($("#c_inner").height()+10)+"px");
		}
		//$("#middle").css("overflow","auto");
	}
	else {
		if($.browser.msie) {
			if(($("#rightBg").length == 0 && $("#rightBg_I").length == 0)) {
				$("#middle").css("width","100%");
				$(".contentWide1").css("width","100%");
				$(".inner").css("width","90%");
			}
		}
	}
	
	if($("#c_inner").height() > $("#left").height()) {
		$("#left").css("height",$("#c_inner").height()+"px");
		$("#middle").css("height",$("#c_inner").height()+"px");
		$("#rightBg").css("height",$("#c_inner").height()+3+"px");
		$("#rightBg_I").css("height",$("#c_inner").height()+3+"px");
		
		if($.browser.msie && jQuery.browser.version == "6.0"){
			if($("#left").height() < $("#middle").height()) {
				var dist = $("#middle").height() - $("#left").height();
				$("#left").css("padding-bottom",dist-4+"px");
			}
			$("#rightBg").css("padding-bottom","15px");
			$("#rightBg_I").css("padding-bottom","15px");
		}
	}
	
	else if($("#c_inner").height() < $("#left").height()) {
		$("#c_inner").css("height",$("#left").height()+"px");
		$("#middle").css("height",$("#left").height()+"px");
		$("#rightBg").css("height",$("#left").height()+3+"px");
		$("#rightBg_I").css("height",$("#left").height()+3+"px");
		
		if($.browser.msie && jQuery.browser.version == "6.0"){
			if($("#left").height() < $("#middle").height()) {
				var dist = $("#middle").height() - $("#left").height();
				$("#left").css("padding-bottom",dist-4+"px");
			}
			$("#rightBg").css("padding-bottom","15px");
			$("#rightBg_I").css("padding-bottom","15px");
		}
		if($.browser.msie && jQuery.browser.version == "7.0"){
			var lsearch = window.location.search;
			var cheight = $("#left").height()+$("#service").height();
			if(lsearch.indexOf("id=86") != -1) { cheight = $("#left").height(); }
			$("#c_inner").css("height",cheight+"px");
			$("#middle").css("height",cheight+"px");
			$("#rightBg").css("height",cheight+3+"px");
			$("#rightBg_I").css("height",cheight+3+"px");
		}
	}
	
	var completeheight = 0;
	$.each($(".xnav3"),function() { completeheight = completeheight+$(this).height()+13; });
	if(completeheight > $("#c_inner").height()) {
		$("#c_inner").css("height",completeheight+20+"px");
		$("#left").css("height",completeheight+20+"px");
		$("#middle").css("height",completeheight+20+"px");
		$("#rightBg").css("height",completeheight+23+"px");
		$("#rightBg_I").css("height",completeheight+23+"px");
	}

	if($("#nav3wrapper").length != 0) {
		if($("#nav3wrapper").html().length == 0) {
			$("#nav3wrapper").hide();
		}
	}
	
	var nheight = $("#navigation").height()+$("#service").height()+8;
	if(nheight >= 562) {
		//var diff = $("#left").outerHeight() -565;
		// $("#middle").css("height",(nheight+14)+"px");
		//$("#middle2").css("height",(nheight+14)+"px");
		//$("#rightBg").css("height",(nheight+11)+"px");
		//$("#rightBg_I").css("height",(nheight+11)+"px");
	}
	$("#rightpicDiv").hide();
	$("#rightpicDiv").show();
	$(".rightpics_lowedge").hide();
	$(".rightpics_lowedge").show();
}

window.onload = correct_sizes;

	function popup(id,lang,typ) {
	
		// Standard
		var attribute3 = "location=no,menubar=no,toolbar=no,status=no,resizable=no,scrollbars=yes,width=595,height=600,left=0,top=0";
		
		// Gesamte Breite
		var attribute5 = "location=no,menubar=no,toolbar=no,status=no,resizable=no,scrollbars=yes,width=810,height=600,left=0,top=0";
		
		var subwindow = 0;
	
		if(typ == 5) {
			var att = attribute5;
		} else {
			var att = attribute3;
		}
		
		if(id==500) {
			sbegriff = $("#sbg").attr("value");
			start = parseInt($("#apage").attr("value"))-1;
			nstart = $("#stbn").attr("value");
			subwindow = window.open("/index.php?start="+start+"&nstart="+nstart+"&suche="+escape(sbegriff)+"&id=" + id + "&type=" + typ + "&L=" + lang +"","popup",att);
		} else {
			subwindow = window.open("/index.php?id=" + id + "&type=" + typ + "&L=" + lang +"","popup",att);
		}
		
		//subwindow = window.open("/index.php?id=" + id + "&type=" + typ + "&L=" + lang +"","popup",att);
	}

	function checkLogin() {
		if($("input:radio[name='agb']:checked").val() == 1) {
			$('#feloginError').css('display','none');
			$('#felogin').submit();
		}	else {
			$('#feloginError').css('display','block');
		}		
	}	

	// In Navigation werden die Abstände korrekt ausgerichtet
	function navigation()	{
		var a = 0;
		$('#navigation .ActiveNow').each(function(){
			a = 1;
		});	
		
		// Home ist nicht aktive
		if($($('#navigation div:first-child')).attr("class") == 'notActiveNow' && a == 1) {
			$('#navigation .notActiveNow:nth-child(1)').addClass('leftTopEnd2');
			$('#navigation .ActiveNow').before('<div class="spacer"></div>');
		} 
		// Home ist die aktuelle Ebene
		else if($($('#navigation div:first-child')).attr("class") == 'ActiveNow')	{
			$('#navigation .ActiveNow:nth-child(1)').addClass('ActiveNow2');
			$('#navigation .ActiveNow2:nth-child(1)').removeClass('ActiveNow');
		
		// wenn keine Ebene aktiv ist
		} else	{
			$('#navigation .notActiveNow:nth-child(1)').addClass('leftTopEnd2');
		}
	}

	// wechselt die aktuelle Sprache
	function languageChange(i) {
		if(i == 0) {
			$('#langHide').show();
		} else	{
			$('#langHide').hide();
		}
	}

	// Serviceicons tauschen
	function changeServiceIcons(i) {	
		if($('#' + i).attr('src') == 'fileadmin/templates/images/'+i+'.gif') {
			$('#'+i).attr('src','fileadmin/templates/images/'+i+'A.gif');
		} else	{
			$('#'+i).attr('src','fileadmin/templates/images/'+i+'.gif');
		}
	}

function openURL(URL) {
	my_window = window.open(URL, "popup", "width=800, height=700");
}
