window.onload = navi;

function getKurs() {
	HTTP_GET_VARS=new Array();
	strGET=document.location.search.substr(1,document.location.search.length);
	if(strGET!='') {
		gArr=strGET.split('&');
		for(i=0;i<gArr.length;i++) {
			v='';
			vArr=gArr[i].split('=');
			if(vArr.length>1) {
				vArr[1];
			}
			HTTP_GET_VARS[unescape(vArr[0])]=unescape(vArr[1]);
		}
	}
	return HTTP_GET_VARS;
}
	
function GET(v) {
	HTTP_GET_VARS = getKurs();
	if(!HTTP_GET_VARS[v]){
		return '0';
	}
	return HTTP_GET_VARS[v];
}

function navi() {
	var ul = $('#subnavi ul').get(0);
	var active = $('.activeMenu').get(0);
	if (!active) { return true; }
	var ul2 = $(ul);
	var active2 = $(active);
	if (ul.offsetWidth + (active.offsetLeft-5) > 750) {
		ul.style.marginLeft=(750)-ul2.width()-(20)+'px';
	} else {
		ul.style.marginLeft=(active.offsetLeft-48)+'px';
	}
}

function f1() {
	var width = $("#popup-iframe").find("img.show").width();
	var height = $("#popup-iframe").find("img.show").height();
	$("#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="fileadmin/templates/dentalklinik/images/close.png" border="0" alt="Schlie&szlig;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.dentalklinik.at/fileadmin/dentalklinik/Videos/"+$(this).attr("href").replace(/.*\//,"");
		$(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="fileadmin/templates/dentalklinik/images/close.png" border="0" alt="Schlie&szlig;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"></a>');
		$('a.media').media( { width: 490, height:290 } );
		var width = 490;
		var height = 290;
		$("#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)-15)+"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.dentalklinik.at/fileadmin/dentalklinik/Videos/"+$(this).attr("href").replace(/.*\//,"");
		$(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="fileadmin/templates/dentalklinik/images/close.png" border="0" alt="Schlie&szlig;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>');

		var width = 640;
		var height = 480;
		$("#popup-iframe").append('<embed src="'+href+'" quality="high" width="'+width+'" height="'+height+'" pluginspage="http://macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" style="display:block;"></embed>');
		/*$("#popup-iframe").append('<a href="'+href+'" class="media { width:300, height:400, autoplay:1 }"></a>');
		$('a.media').media( { autoplay: 1 });*/
		$("#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)-15)+"px");
		$("#popup-closer").click(function(e){
			e.preventDefault();
			$("#popup-iframe").remove();
			$(this).remove();
			$("#darker").fadeOut("slow",function(){
				$(this).remove();
			});
		});
	});

});