/** Load thumbnails **/
function thumbv2(pic, tw, th) {
	
	var w = pic.width();
	var h = pic.height();
	var aspect, diff;
	if(w==0 || h==0) return null; // 404?
	//alert("starting size: " +width+" "+height);

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

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

		if(h>th) { // picture is taller than canvas, so trip top and bottom
			diff = (h - th)/2;
			pic.css("margin-top",-diff);
			pic.css("margin-bottom",-diff);
		}
		else if(h<th) { // picture is shorter than canvas, so stretch left and right
			h = th;
			w = th/aspect;
			
			diff = (w - tw)/2;
			pic.css("margin-left",-diff);
		}
	}
	pic.css("width",w +"px");
	pic.css("height",h +"px");
	pic.parent().css("width",tw +"px");
	pic.parent().css("height",th +"px");
	//pic.css("display","inline");
	pic.fadeIn("slow");
}
