/** Load thumbnails **/
function thumb(pic) {
	
	var width = pic.width();
	var height = pic.height();

	if(height>width) { // image is tall, so top/bottom has to be cropped
		// width should equal thumbw, height is calculated, then margins cropped
		aspect = height/width;
		width = thumbw;
		height = thumbw*aspect;

		// center image in LI
		if(height>thumbh) {
			diff = -(thumbh-height)/2;
			pic.css("bottom",diff);
		}	
	}
	else { // picture is wide - make sure the picture is tall enough. otherwise, stretch image sideways
		aspect = height/width;
		width = thumbw;
		height = thumbw*aspect;

		if(height>thumbh) { // picture is taller than canvas, so trip top and bottom
			diff = (height - thumbh)/2;
			pic.css("margin-top",-diff);
			pic.css("margin-bottom",-diff);
		}
		else if(height<thumbh) { // picture is shorter than canvas, so stretch left and right
			height = thumbh;
			width = thumbh/aspect;
			
			diff = (width - thumbw)/2;
			pic.css("margin-left",-diff);
		}
	}
	pic.css("width",width);
	pic.css("height",height);
}
