$(function() {
	$('.project/.post/.entry/ul/li/.showcase').hide();
	$('.project/.post/.entry/ul/li/.showcase').parent('li').prepend('<a href="#" class="toggle_images">dun dun</a>');
	$('.toggle_images').click(function() {
		($(this).siblings('.showcase').is(':hidden')) ? $(this).addClass('expanded') : $(this).removeClass('expanded');
		images = $(this).siblings('.showcase');
		images.slideToggle('slow', function(){images.css('height', 'auto');});
		
		return false;
	});
	
	
	
	$('.showcase/a/img').parent('a').click(function() {
		href = $(this).href();
		var ext = href.substring(href.lastIndexOf('.') + 1, href.length);
		
		if (ext == 'jpg' || ext == 'gif') {
			image = new Image();
			image.onload = function() {
				var height = (image.height > 520) ? 520 : image.height;
				var width = (image.width > 720) ? 720 : image.width;
				width = (height == 520) ? width + 16 : width;
				var scrollbars = (height == 520 || width == 720) ? 'yes' : 'no';
				
				popup=window.open(href, "popup", "top=80,left=80,width=" + width + ",height=" + height + ",scrollbars=" + scrollbars + ",toolbar=no,location=no,directories=no,status=no,menubar=no");
				if (popup) { popup.document.write('<html><head><style type="text/css">body { margin: 0; padding: 0; }</style></head><body>');
					popup.document.write('<img src="' + href + '" width="' + image.width + '" height="' + image.height + '" />');
					popup.document.write('</body></html>');
					popup.focus();
					popup.document.close();
				}
				else {
					alert('Please disable your popup blocker for this website.');
				}
			}
			image.src = href;
			
			return false;
		}
	});
});