$(document).ready(function() {

	$.include('jquery/jquery.blockUI.js', function() {

		$.extend({
			
			resizeLayer: function(contentHeight, doAnimate) {
				
				var minHeight = 100;
				var maxHeight = $(window).height() - 150;
				var setHeight = contentHeight + 50;
				
				// Mindesthoehe
				if (setHeight < minHeight) setHeight = minHeight;
				// Maximalhoehe
				if (setHeight > maxHeight) setHeight = maxHeight;
				
				if (doAnimate == true) {
					$(".blockPage").animate({"height": setHeight}, {duration: "slow"});
				} else {
					$(".blockPage").height(setHeight);
				}
				$(".blockPage iframe").height(setHeight - 50);
				
			},
			
			loadContent: function(url, forceHeight, forceWidth, handleSameWindow) {
				
				var iframe = $('<iframe frameborder="no" scrolling1="auto"></iframe>');
				
				if (url != undefined) {
					iframe.attr("src", url);
				}
				
				iframe.css("width", "100%").css("border", "1px dotted #C0C0C0")
					.css("position", "absolute").css("left", "-999px");
				
				var doWidth = forceWidth != null ? forceWidth : 760;
				
				$.blockUI({
		            message: iframe,
		            fadeIn: 50,
		            fadeOut: 700,
		            centerY: false,
		            allowBodyStretch: true,
		            css: {
						left: '80px', top: '100px', width: doWidth + 'px', height: '20px',
		                border: 'none', padding: '5px 15px 0 15px',
		                backgroundColor: '#EFEFEF',
		                '-webkit-border-radius': '10px',
		                '-moz-border-radius': '10px',
		                color: '#FFF'
		            }
				});
	
				iframe.load(function() {
	
					var iframeContent = iframe.contents();
					var content = iframeContent.find("#col1_content");
					var contentHeight = content.height() + 35;
					
					var contentTitle = content.find("h1:first");
					var topLayer = $("<div></div>").css("cursor", "auto").css("height", "35px");
					
					if (contentTitle.html()) contentTitle.remove();
					iframeContent.find("html").height("0");
					
					iframeContent.find("body").empty().removeClass("zweispaltig").addClass("einspaltig").css("background-color", "#FFFFFF");
					content.appendTo(iframeContent.find("body"));
					
					if (handleSameWindow != true) iframeContent.find("a, form").attr("target", "_top");
					$(this).unbind();
					
					$('<a href="#" class="closeButton">[x]</a>').css("float", "right").css("padding", "5px").appendTo(topLayer);
					if (contentTitle.html()) $("<h1>" + contentTitle.html() + "</h1>").css("padding-top", "5px").appendTo(topLayer);
					topLayer.insertBefore(iframe);
					
					iframe.css("position", "static").css("left", "0");
					
					if ($.browser.msie && $.browser.version == 7) iframeContent.find("body").css("min-height", "1%");
					
					var doHeight = (forceHeight != null) ? forceHeight : contentHeight;
					
					if (!($.browser.msie && $.browser.version == 7)) $(window).resize(function() {$.resizeLayer(doHeight, false)});
					$.resizeLayer(doHeight, true);
	
					$('.blockOverlay, .closeButton').click(function() {
						$.unblockUI({onUnblock: function() {$('.blockUI').remove()}}); /* fix for IE */
						iframe = null;
						return false;
					});
					
				});
				
				return iframe;
			
			}
		
		});
		
		// Trigger
		$("a.layerContent").click(function() {
			$.loadContent($(this).attr("href"));
			return false;
		});
	
	});
	
});