$jQ(document).ready(function(){
        $jQ("[class='turtleThumb']").each(function(){            
               $jQ(this).find("img").css("opacity","0");
         });
});

$jQ(window).bind('load', function() {

    	$jQ("[class='turtleThumb']").each(function(){
               
               $jQ(this).find("img").css("opacity","0")

		//Add relevant CSS
		$jQ(this).css("position","relative");
		$jQ(this).find("img").css("position","absolute");
		$jQ(this).find("img").css("left","0");
			
		//Attain the measurements for image and container
		var cw = $jQ(this).width();
		var ch = $jQ(this).height();
		var tw = $jQ(this).find("img").width();
		var th = $jQ(this).find("img").height();

		//Measurement ratios
        var tratio = (th/tw);
		var cratio = (ch/cw);
		var thperc = (ch/th);	
		var twperc = (cw/tw);	
		var newtw = (thperc*tw);	
		var newth = (twperc*th);	

			//container ratio is larger
			if (cratio>tratio) {
				$jQ(this).find("img").height(ch);			
							
				if(newtw>cw) {
					var centertw = (newtw-cw)/2;
					$jQ(this).find("img").css("left" , -centertw); }
				else if (newtw<cw)	{
						$jQ(this).find("img").width(cw); }
			}

			//container ratio is smaller
			else if (cratio<tratio) {
	                $jQ(this).find("img").width(cw);			
					
					if(newth>ch) {
						var centerth = (newth-ch)/2;
						$jQ(this).find("img").css("top" , -centerth); }
					else if (newth<ch)	{
						$jQ(this).find("img").height(ch); }
			}
	 
			//Container and Thumb ratio are same		
			else {			
				$jQ(this).find("img").width(cw);
				$jQ(this).find("img").height(ch);
			}

       $jQ(this).find("img").fadeTo("slow", 1);

				
	});


});

