
// Funktion zum Anzeigen und Animieren des Modalen Fensters
function umschalt(title,hoehe,breite) {
	$("#picpopup").hide();
	$("#closeimg").hide();
	$("#popupwrapper").css("visibility","visible");
	$("#popupwrapper").css({'width':'200px','height':'200px'});

	$("#popupwrapper").animate({ 
		
		height:hoehe+60,
		width:breite
	}, 500, function() {

		$("#popupwrapper").animate({ width: breite}, 0, function() {
				if (title != null) {
					$("#picpopup").fadeIn(400);
					$("#closeimg").fadeIn(2000);					
					$("#popupwrapper").append("<p>"+title+"</p>");
				}
		});
	});

	$("#closeimg").click(function(event) {
		$("#bgpopup").fadeOut('slow', function() {
			$('#bgpopup').remove();
		});
	});
}

$(document).ready(function() {
	$("a.lupe").click(function(event) {
		if (navigator.appVersion.indexOf("MSIE 8") == -1) {
			event.preventDefault();
			$(document).css("cursor","wait");
			var title = event.target.getAttribute("title");
			if (title == null) title = event.target.getAttribute("alt");
			if (title == null) title = "";
			var imgUrl  = event.currentTarget;
			$("body").append('<div id="bgpopup"></div>');
			$("#bgpopup").append('<div id="popupwrapper"></div>');
			document.getElementById("bgpopup").style.height = $(document).height()+"px";
			$("#popupwrapper").append('<p align="right" style="margin-bottom:20px;"><img id="closeimg" src="frame/closemodalwindow.png" /></p>');
			$("#popupwrapper").append('<p><img id="picpopup" name="picpopup" src="'+imgUrl+'" /></p>');
			$("#bgpopup").css("visibility","visible");
			$("#popupwrapper").css("visibility","hidden");
			$("#closeimg").css("display","none");
			$("#closeimg").css("visibility","visible");
			var vertPos = window.pageYOffset + 25;
			$("#popupwrapper").css("margin-top",vertPos+"px");
			$("#bgpopup").fadeIn(50,function() {
				if (document.images["picpopup"].complete) {
					var breite = $("#picpopup").width();
					var hoehe = $("#picpopup").height();
					umschalt(title,hoehe,breite);
				} else {
					$("#picpopup").one("load",function(){
						var breite = $("#picpopup").width();
						var hoehe = $("#picpopup").height();
						umschalt(title,hoehe,breite);
					}).each(function(){
						if(this.complete) $(this).trigger("load");
					});
				}
			});
		}
	});
	$("#oberkante a").click(function(event) {
		event.preventDefault();
		alert($("#oberkante").offset().top);
	});
 });
