$(document).ready(function(){
	$('a#single_image').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
		});	
	
	
	});

$(window).load(function() {

		$('a#single_image img').each(function() {
		
			 	var maxWidth = 250; // Max width for the image
				var maxHeight = 400;    // Max height for the image
				var ratio = 0;  // Used for aspect ratio
				var width = $(this).width();    // Current image width
				var height = $(this).height();  // Current image height
				
				$(this).removeAttr('width');
				$(this).removeAttr('height');
				
				//alert('pre width: '+width+' pre height: '+height);
				
				var aspectRatio = 0;
				var aspectRatio = width/height;
				
				if (width >= height) {
				
					var newWidth = (width > maxWidth) ? maxWidth : width;
					var newHeight = height * (newWidth/height);
					
					$(this).css("width", newWidth); // Set new width
					$(this).css("height", newHeight);  // Scale height based on ratio
				
					}


				if (height > width) {
				
					var newHeight = (height > maxHeight) ? maxHeight : height;
					var newWdith = width * (newHeight/width);
					
					$(this).css("width", newWidth); // Set new width
					$(this).css("height", newHeight);  // Scale height based on ratio
				
					}
					
				});

	});

