$(document).ready(function() {
	
});

function loadPopupWindow(targetElement) {
	$(targetElement).colorbox({
		width: '700px',
		opacity: '0.7',
		transition: 'none',
		maxHeight: '700px',
		onComplete: function() {
			$("head").append("<link>");
			css = $("head").children(":last");
			css.attr({
				media: "print",
				href: "/css/print-popup.css",
				type: "text/css",
				rel:  "stylesheet"
			});
		
			$('#popup .print').click(function() {
				window.print();
			});
		},
		onCleanup: function() {
			$('head').children(':last').remove();
		}
	});
}
function loadKontaktWindow(targetElement) {
	$(targetElement).colorbox({
		width: '700px',
		opacity: '0.7',
		transition: 'none',
		maxHeight: '700px',
		onComplete: function() {
			$("head").append("<link>");
			css = $("head").children(":last");
			css.attr({
				media: "print",
				href: "/css/print-popup.css",
				type: "text/css",
				rel:  "stylesheet"
			});
		
			$('#popup .print').click(function() {
				window.print();
			});
			
			//$('#fSubmit').click(function() { kontaktFormAjax(); });
			$('#kontaktForm').submit(function() { kontaktFormAjax(); return false; });
		},
		onCleanup: function() {
			$('head').children(':last').remove();
		}
	});
}

function kontaktFormAjax() {
	//alert($('#kontaktForm').serialize());
	$.post('kontakt-formular.html', $('#kontaktForm').serialize() + '&fSubmit=Absenden', function(data) {
		$('#cboxLoadedContent').html(data);
		
		// Höhe des Fensters neu berechnen
		refreshPopupHeight();
		
		// OnSubmit Event neu setzen
		$('#kontaktForm').submit(function() { kontaktFormAjax(); return false; });
	});
}

function refreshPopupHeight() {
	$('#cboxLoadedContent').css("height", null);
	$('#cboxContent').css("height", null);
	$('#cboxWrapper').css("height", null);
	$('#colorbox').css("height", null);
	
	$('#cboxLoadedContent').css("height", $('#cboxLoadedContent').height());
	$('#cboxContent').css("height", $('#cboxContent').height());
	$('#cboxWrapper').css("height", $('#cboxWrapper').height());
	$('#cboxMiddleLeft').css("height", $('#cboxContent').height());
	$('#cboxMiddleRight').css("height", $('#cboxContent').height());
	$('#colorbox').css("height", $('#cboxWrapper').height());
	//$('#zumkontakt').colorbox.resize();
}
