function f1() {
	var width = $("#popup-iframe").find("img.show").width();
	var height = $("#popup-iframe").find("img.show").height();
	
	if(width>600) {
		$("#popup-iframe").find("img.show").css("width","600px");
		var tempH = (600*height)/width;
		$("#popup-iframe").find("img.show").css("height",tempH+"px");
		width = 600;
		height = tempH;
	}
	
	$("#popup-iframe").css("margin-left",((-width/2))+"px");
	$("#popup-iframe").css("margin-top",((-height/2))+"px");
	$("#popup-closer").css("margin-left",((width/2)-10)+"px");
	$("#popup-closer").css("margin-top",((-height/2)-10)+"px");
	$("#popup-closer").click(function(e){
		e.preventDefault();
		$("#popup-iframe").remove();
		$(this).remove();
		$("#darker").fadeOut("slow",function(){
			$(this).remove();
		});
	});
	$("#popup-closer,img.show").show();
}
		
function setFullHeight(layer) {
	var bodyHeight = $('body').height();
	var windowHeight = $(window).height();
	var h = (bodyHeight > windowHeight ? bodyHeight : windowHeight);
	$(layer).height(h);
}

$(document).ready(function(){

	$(".news-list-item").find("img:first").each(function(){
		if($(this).parents(".news-list-item").find("a[href*=.jpg]").length==0) return;
		var temp_href = $(this).parents(".news-list-item").find("a[href*=.jpg]").filter(":first").attr("href");
		if(temp_href.indexOf(".jpg")==-1) return;
		$(this).css("cursor","pointer");
		$(this).click(function(){
			$(this).parents(".news-list-item").find("a[href*=.jpg]").filter(":first").click();
		});
	});
	
	$(".news-list-item").find("a").click(function(e){
		var temp_href = $(this).attr("href");
		if(temp_href.indexOf(".jpg")==-1) return;
				
		e.preventDefault();
		$(document).scrollTop(0);
		$("body").append('<div id="darker" style="position:absolute; top:0px; left:0px; width:100%; background-color:#000;z-index:4000; display:none;"></div>');
		$("#darker").css('opacity',0.6).fadeIn("slow");
		setFullHeight($("#darker"));
		$("body").append('<a href="#" id="popup-closer" style="position:absolute; display:none; top:50%; left:50%; margin-left:320px; margin-top:-285px; z-index:4050;"><img src="uploads/tf/haubis-close-button.png" border="0" alt="Schließen" /></a>');
		$("body").append('<div id="popup-iframe" style="position:absolute; top:50%; left:50%; margin-left:-338px; margin-top:-269px; z-index:4030; background:none;"></div>');
		$("#popup-iframe").append('<img class="show" src="'+temp_href+'" style="cursor:pointer; display:none;" />');
		$("#popup-iframe").find("img.show").each(function(){
			this.onload = f1;	
		});
	});
	
	$("a[href*=.flv]").click(function(e){
		e.preventDefault();
		var href="http://www.haubis.at/"+$(this).attr("href").replace("http://www.haubis.at/","");
		$(document).scrollTop(0);
		$("body").append('<div id="darker" style="position:absolute; top:0px; left:0px; width:100%; background-color:#000;z-index:4000; display:none;"></div>');
		$("#darker").css('opacity',0.6).fadeIn("slow");
		setFullHeight($("#darker"));
		$("body").append('<a href="#" id="popup-closer" style="position:absolute; top:50%; left:50%; margin-left:320px; margin-top:-285px; z-index:4050;"><img src="uploads/tf/haubis-close-button.png" border="0" alt="Schließen" /></a>');
		$("body").append('<div id="popup-iframe" style="position:absolute; top:50%; left:50%; margin-left:-338px; margin-top:-269px; z-index:4030; background:none;"></div>');
		$("#popup-iframe").append('<a href="'+href+'" class="media { width:300, height:400 }"></a>');
		$('a.media').media();
		var width = 400;
		var height = 300;
		$("#popup-iframe").css("margin-left",(-width/2)+"px");
		$("#popup-iframe").css("margin-top",(-height/2)+"px");
		$("#popup-closer").css("margin-left",((width/2)-10)+"px");
		$("#popup-closer").css("margin-top",((-height/2)-10)+"px");
		$("#popup-closer").click(function(e){
			e.preventDefault();
			$("#popup-iframe").remove();
			$(this).remove();
			$("#darker").fadeOut("slow",function(){
				$(this).remove();
			});
		});
	});
	

	$("a[href*=.swf]").click(function(e){
		e.preventDefault();
		var href="http://www.haubis.at/"+$(this).attr("href").replace("http://www.haubis.at/","");
		$(document).scrollTop(0);
		$("body").append('<div id="darker" style="position:absolute; top:0px; left:0px; width:100%; background-color:#000;z-index:4000; display:none;"></div>');
		$("#darker").css('opacity',0.6).fadeIn("slow");
		setFullHeight($("#darker"));
		$("body").append('<a href="#" id="popup-closer" style="position:absolute; top:50%; left:50%; margin-left:320px; margin-top:-285px; z-index:4050;"><img src="uploads/tf/haubis-close-button.png" border="0" alt="Schließen" /></a>');
		$("body").append('<div id="popup-iframe" style="position:absolute; top:50%; left:50%; margin-left:-338px; margin-top:-269px; z-index:4030; background:none;"></div>');
		/*$("#popup-iframe").append('<a href="'+href+'" class="media { width:300, height:400 }"></a>');
		$('a.media').media();*/
		var width = 600;
		var height = 500;
		$("#popup-iframe").append('<div id="popup-swf"></div>');
		$("#popup-iframe").find("#popup-swf").flash({
			src : $(this).attr("href"),
			width : '600px',
			height : '500px',
			wmode : 'transparent'			
		});
		$("#popup-iframe").css("margin-left",(-width/2)+"px");
		$("#popup-iframe").css("margin-top",(-height/2)+"px");
		$("#popup-closer").css("margin-left",((width/2)-10)+"px");
		$("#popup-closer").css("margin-top",((-height/2)-10)+"px");
		$("#popup-closer").click(function(e){
			e.preventDefault();
			$("#popup-iframe").remove();
			$(this).remove();
			$("#darker").fadeOut("slow",function(){
				$(this).remove();
			});
		});
	});
	
	if(self.location.href.indexOf("#kickerweckerl")!=-1) {
		open_gewinnspiel()
	}

});

function open_gewinnspiel() {
				try {
				var pageTracker = _gat._getTracker("UA-9444591-1");
				pageTracker._trackPageview("kickerweckerl");
				} catch(err) {}
					
				$ = jQuery;
				$("body").append(''+
					'<div id="imgbox">'+
						'<div id="background"></div>'+
						'<div id="element">'+
							'<div class="img"><a href="fileadmin/pdf/kickerweckerl.pdf"><img style="border:none" src="'+"fileadmin/pdf/kickerweckerl.gif"+'" /></a></div>'+
						'</div>'+
						'<div class="close">'+
							'<img src="uploads/tf/haubis-close-button.png" alt="close" />'+
						'</div>'+
					'</div>'+
				'');
				
				/*
				Lightbox CSS
				*/
				$("#imgbox").css({
					"position":"fixed",
					"top":"0px",
					"left":"0px",
					"width":"100%",
					"height":"100%",
					"zIndex" : 4000
				});
				
				$("#imgbox .img img").load(function(){
				
					/*
					Deklarationen
					*/
					var width = 664;
					var height = 561;
					
					/*
					Maximal Breite Festlegen
					*/
				
					/*
					Background CSS
					*/
					$("#background").css({
						"position":"absolute",
						"top":"0px",
						"left":"0px",
						"width":"100%",
						"height":"100%",
						"background":"#000",
						"opacity":0.5
					}).hide();
					
					/*
					Element CSS
					*/
					$("#element").css({
						"position":"absolute",
						"top":"50%",
						"left":"50%",
						"zIndex":4010
					});
						var marginLeft = width/2 * -1;
						var marginTop = height/2 * -1;
					$("#element").css({
						"width":width,
						"height":height,
						"marginLeft":marginLeft,
						"marginTop":marginTop
					});
					
					/*
					Close Button CSS
					*/
					$("#imgbox .close").css({
						"position":"absolute",
						"top":"50%",
						"left":"50%",
						"zIndex":4020,
						"marginLeft" : -marginLeft + 10,
						"marginTop" : marginTop -10,
						"cursor" : "pointer"
					});
					
					/*
					Close Button Event
					*/
					$("#imgbox .close").click(function(){
						$("#imgbox").remove();
						$("#element").remove();
						$("#background").fadeOut("slow",function(){
							$("#imgbox").remove();
						});
					});
					
					/*
					FadeIn
					*/
					$("#background").show();
				});
				
				
}