// JavaScript Document

function center(target,animate) {
	cw=$(window).width();
	ch=$(window).height();
	ow=$(target).outerWidth();
	oh=$(target).outerHeight();
	w=$(target).width();
	h=$(target).height();
	
	t=(ch-oh)/2+$(window).scrollTop();
	if (t<$(window).scrollTop()) t=$(window).scrollTop();
	
	if (animate>0) {
		$(target).width(0);
		$(target).height(0);
		$(target).css('opacity',0);
		$(target).css('left',cw/2);
		$(target).css('top',ch/2+$(window).scrollTop());
		$(target).animate({left:(cw-ow)/2,top:t,width:w,height:h,opacity:1},animate);
	} else {
		$(target).css('left',(cw-ow)/2);
		$(target).css('top',t);
	}
}

function enlarge(t) {
	$('body').prepend('<div id="enlargePicture" style="background:#fff;border:15px solid #fff;position:absolute;box-shadow:#000 0 4px 10px;cursor:wait"><span style="font-family:sans-serif;font-size:11px">...</span><img src="'+t.href+'" alt="" style="display:none"></div>');
	$('#enlargePicture IMG').load(function(e) {
		$('#enlargePicture SPAN').hide();
		$('#enlargePicture IMG').css('display','block');
		$('#enlargeBackground, #enlargePicture').css('cursor','pointer');
		center('#enlargePicture',200);
	});
	$('body').prepend('<div id="enlargeBackground" style="background:#000;opacity:0.7;filter:alpha(opacity=70);position:fixed;left:0;top:0;bottom:0;right:0;cursor:wait;display:none"></div>');
	$('#enlargeBackground').fadeIn(200);
	center('#enlargePicture');
	$('#enlargeBackground, #enlargePicture').click(function(e) {
		$('#enlargeBackground').fadeOut(200,function() {$('#enlargeBackground').detach()});
		$('#enlargePicture').fadeOut(200,function() {$('#enlargePicture').detach()});
	});
	return false;
}

$(document).ready(function(e) {
	$('.enlarge').click(function(e) {
		return enlarge(this);
	});
});
