jQuery(document).ready(function($){
	$("a[target=immo-factsheet]").click(function(e){
		e.preventDefault();
		$(document).scrollTop(0);
		$("body").darker(1000);
		$("body").preloader("fileadmin/tmpl/ladebalken.gif",0);
		
		$("body").append('<div id="immo-factsheet"></div>');
		$("body").find("#immo-factsheet")
			.css("position","absolute")
			.css("top","50%")
			.css("left","50%")
			.css("margin-left","-400px")
			.css("margin-top","-198px")
			.css("width","800px")
			.css("height","396px")
			.css("z-index","2030")
			.css("display","none")
			.css("background","#fff");
			
		$("body").find("#immo-factsheet").append('<iframe src="'+$(this).attr("href")+'" frameborder="0" border="0" scrolling="no"></iframe>');
		$("body").find("#immo-factsheet").find("iframe")
			.css("width","100%")
			.css("height","100%");
		
		$("body").append('<a href="#" id="immo-factsheet-closer"><img src="fileadmin/tmpl/factsheet-closer.png" alt="Schließen" /></a>');
		$("body").find("#immo-factsheet-closer")
			.css("position","absolute")
			.css("top","50%")
			.css("left","50%")
			.css("margin-top","-198px")
			.css("margin-left","410px")
			.css("z-index","2030")
			.css("display","none");
			
		$("body").find("#immo-factsheet").find("iframe").load(function(){
			$("body").closePreloader(1000,function(){
				$("#immo-factsheet-closer").show();
				$("#immo-factsheet").show();
				
				$("#immo-factsheet-closer").click(function(e){
					e.preventDefault();
					location.hash = '';
					
					
					
					$("#immo-factsheet,#immo-factsheet-closer").remove();
					$("body").closeDarker("slow");
				});
				
			});
		});
	});
	
	$("a[target=immo-factsheet2]").click(function(e){
		e.preventDefault();
		$(document).scrollTop(0);
		$("body").darker(1000);
		$("body").preloader("fileadmin/tmpl/ladebalken.gif",0);
		
		$("body").append('<div id="immo-factsheet"></div>');
		$("body").find("#immo-factsheet")
			.css("position","absolute")
			.css("top","50%")
			.css("left","50%")
			.css("margin-left","-434px")
			.css("margin-top","-250px")
			.css("width","867px")
			.css("height","518px")
			.css("z-index","2030")
			.css("display","none")
			.css("background","#fff");
			
		$("body").find("#immo-factsheet").append('<iframe src="'+$(this).attr("href")+'" frameborder="0" border="0" scrolling="no"></iframe>');
		$("body").find("#immo-factsheet").find("iframe")
			.css("width","100%")
			.css("height","100%");
		
		$("body").append('<a href="#" id="immo-factsheet-closer"><img src="fileadmin/tmpl/factsheet-closer.png" alt="Schließen" /></a>');
		$("body").find("#immo-factsheet-closer")
			.css("position","absolute")
			.css("top","50%")
			.css("left","50%")
			.css("margin-top","-279px")
			.css("margin-left","424px")
			.css("z-index","2030")
			.css("display","none");
			 
		/*$("body").find("#immo-factsheet").find("iframe").load(function(){
			$("body").closePreloader(1000,function(){
				$("#immo-factsheet-closer").show();
				$("#immo-factsheet").show();
				
				$("#immo-factsheet-closer").click(function(e){
					e.preventDefault();
					$("#immo-factsheet,#immo-factsheet-closer").remove();
					//$("body").closeDarker("slow");
				});
				
			});
		});*/
		

			$("body").closePreloader(1000,function(){
				$("#immo-factsheet-closer").show();
				$("#immo-factsheet").show();
				
				$("#immo-factsheet-closer").click(function(e){
					
					location.hash = "";
				
					e.preventDefault();
					$("#immo-factsheet,#immo-factsheet-closer").remove();
					$("body").closeDarker("slow");
				});
				
			});

	});
	
	$('a[href*=#immo]').click(function(){


		
		if($("a#immo").length>0)
		{
			if($("a#immo").next().hasClass("immo"))
			{
				$("a#immo").next().click();
			}
		}
	});
		
	if(self.location.href.indexOf("#")!=1)
	{
		var anker = self.location.href.split("#")[1];
		if($("a#"+anker).length>0)
		{
			if($("a#"+anker).next().hasClass("immo"))
			{
				$("a#"+anker).next().click();
			}
		}
	}
});