$(function() {
	$('#blog .post a').click(function(evt) {
		evt.preventDefault();
					
		var href = this.href;
		if(href.match('files/') != null && href.match('.jpg') != null) {			
			$('#gallery_fade').fadeTo('fast', 0.9).css({'top' : String($(window).scrollTop()) + 'px'});
			$('#gallery_popup_inner').html('<img src="design/img/loading.gif"><br> <br>loading');
			$('#gallery_popup').fadeIn().css({'top' : String($(window).scrollTop() + 100) + 'px'});
			$('#gallery_popup_inner').load('scripts/blog_load.php', { 'file': href }, function(resp) {
				if($('#gallery_popup_inner').html() == 'error') {
					window.open(href, 'wnd');
					$('#gallery_fade').hide();
					$('#gallery_popup').hide();		
				}
				else {
					var width 	= Number($('#gallery_popup_inner').find('img').attr('width'));
					var height 	= Number($('#gallery_popup_inner').find('img').attr('height'));
					var center	= -1 * (width / 2);
					
					$('#gallery_popup').css({
						'width' 		: width + 'px',
						'height' 		: height + 'px',
						'margin-left'	: center + 'px'
					});
					$('#gallery_popup_inner').css({
						'width' 		: width + 'px',
						'height' 		: height + 'px',
						'overflow'		: 'hidden'
					});
				}
			});
		}
	});
});
