$(document).ready(function(){
	var host=window.location.href.replace(/^([a-z0-9]+:\/\/.*?\/).*/i,'$1');
	$('a').bind('click',function(){
		if(this.href.substring(0,host.length)==host){
			var $p=$(
				'<div class="jPopup">'+
					'<div>'+
						'<h2>'+$(this).html()+'</h2>'+
						'<img src="/img/index/close.png" width="17" height="17" alt="Schließen" />'+
						'<iframe src="'+$(this).attr('href')+'" scrolling="no" frameborder="0" allowTransparency="true" marginwidth="0" marginheight="0" ></iframe>'+
					'</div>'+
				'</div>'
			).appendTo('body');
			var $e=$('div',$p);
			$(window).bind('resize',function(){
				$p.css('display','none');
				$p.css({
					display:'block',
					width:$(document).width(),
					height:$(document).height()
				});
				$e.css({
					left:($(document).width()-$e.width())/2,
					top:($(document).height()-$e.height())/2
				});
			}).trigger('resize');
			$('img',$e).bind('click',function(){
				$(this).parent().parent().remove();
			});
			$(document).bind('keyup.jPopup',function(e){
				if(e.which==27){
					$('.jPopup').remove();
					$(document).unbind('.jPopup');
				}
			});
			$('iframe',$e).load(function(){
				var w=$(this).contents().width();
				var h=$(this).contents().height();
				var x=Math.round(($(document).width()-w)/2);
				var y=Math.round(($(document).height()-h)/2);
				$e.css({
					left:(x<0?0:x)+$(window).scrollLeft(),
					top:(y<0?0:y)+$(window).scrollTop(),
					width:w+6
				});
				$('iframe',$e).css({
					height:h
				});
				$('h2',$e).text($(this).contents().find('title').text().replace(/^\s*(.*?)\s*[|].*$/,'$1'));
				$(window).trigger('resize');
			});
		}else if(this.href.length>0){
			window.open(this.href);
		}
		return false;
	});
});
