$(document).ready(function(){
	$('a.lightbox:has(img)').addClass('hasImg');
	$('a.lightbox:has(img) img').before('<span class="plus-btn"></span>');
		
	$('a.lightbox').click(function(e){
		
		$('div#header').before('<div id="lb"><a href="#">close</a><img src="'+ $(this).attr("href") +'" /></div>');
		
		$('div#lb img').load(function(){
			showImg();
		});
		
		function showImg(){
			var destinationY = $(window).scrollTop() + 20,
				winW = $(window).width(),
				winH = $(window).height(),
				thisW = $('div#lb').width(),
				thisH = $('div#lb').height();
			
			$('div#lb img').hide();
			$('div#lb').css({
				'opacity' : 0,
				'margin-top' : 0,
				'margin-left' : 0,
				'width' : 0,
				'height' : 0,
				'top' : e.pageY,
				'left' : ((e.pageX / winW) * 100) + '%',
				'-webkit-box-shadow' : 'none',
				'-moz-box-shadow' : 'none'
			});
			$('div#lb').animate({
				opacity : 1,
				marginLeft : (thisW/2)/-1,
				width: thisW,
				height: thisH,
				top: destinationY + 'px',
				left: '50%'
				
			}, 400, function(){
				$('div#lb img').show();
				$('div#lb').css({
					'-webkit-box-shadow' : '0 0 60px rgba(0, 0, 0, .3)',
					'-moz-box-shadow': '0 0 60px rgba(0, 0, 0, .3)'
				})
			});
		}
		return false;
	});
	$('div#lb a').live('click', function(){
		$('div#lb').fadeOut(200, function(){
			$('div#lb').remove();
		});
		return false;
	});
});

