$(function(){
	$('<div id="curtain">')
	.css({
		'display':'none',
		'background-color':'#000',
		'opacity':'0.5',
		'position':'absolute',
		'width':Math.max( $('body').width(), $('#c0').innerWidth() ),
		'height':$('#c0').innerHeight(),
		'z-index':'100'
	})
	.prependTo($('body'));
	$('<div id="pfshow">')
	.css({
		'display':'none',
		'background':'#FFF url("img/loading.gif") center center no-repeat',
		'border':'solid 1px #090',
		'position':'absolute',
		'width':'600px',
		'height':'90%',
		'z-index':'1000'
	})
	.prependTo($('body'));
	var $close=$('<a href="#close">x</a>')
	.css({
		'display':'block',
		'position':'absolute',
		'right':'0',
		'top':'0',
		'width':'16px',
		'line-height':'16px',
		'overflow':'hidden',
		'text-align':'center',
		'font-weight':'bold',
		'border-left':'solid 1px #090',
		'border-bottom':'solid 1px #090',
		'background-color':'#900',
		'color':'#FFF'
	})
	.click(function(){$('#curtain').click(); return false;});
	$('.portfolio a').click(function(){
		$('#curtain').show().click(function(){
			$('#curtain, #pfshow').hide();
			$(document.body).unbind('scroll');
		});
		$('#pfshow')
		.css('background-image', 'url("img/loading.gif")')
		.width(600)
		.show();
		setPfPosition();
		$('#pfshow')
		.load($(this).attr('href')+' .portfolio_more', '', function(data){
			var $pf=$('#pfshow');
			$pf.append($close);
			$close.click(function(){
				$('#curtain').click();
				return false;
			});
			$pf.css('background-image', 'none')
			.width($pf.find('.portfolio_more').innerWidth())
			.height($pf.find('.portfolio_more').innerHeight())
			;
			$(window).bind('scroll', setPfPosition).trigger('scroll');
		});
		return false;
	});
	function setPfPosition(){
		var $pf=$('#pfshow');
		$pf
		.css('left', Math.max(0, ($('#curtain').width()-$pf.innerWidth())/2))
		.css('top', Math.max(0, (document.documentElement.clientHeight-$pf.innerHeight())/2)+$(document.body).scrollTop());
	}
});
