			/* SCALE IMAGES TO FIT THUMB CONTAINER */
$(document).ready(function() {
	

	$('.thumb_bg img').each(function() {
		var parent = $(this).parent();
		parent.prepend('<div class="loading"></div>')
		var maxWidth = 90; // Max width for the image
        var maxHeight = 90;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
		var imgsrc = $(this).attr('src');  // Current image link
		var href = $(this).parent('a').attr('href');  // Current image link

		var width = $(this).width();    // Current image width
		var height = $(this).height();  // Current image height
		
		// Check if the current width is larger than the max
		if(width > maxWidth){
			ratio = maxWidth / width;   // get ratio for scaling image
			$(this).css("width", maxWidth); // Set new width
			$(this).css("height", height * ratio);  // Scale height based on ratio
			height = height * ratio;    // Reset height to match scaled image
			width = width * ratio;    // Reset width to match scaled image
		}
 
		// Check if current height is larger than max
		if(height > maxHeight){
			ratio = maxHeight / height; // get ratio for scaling image
			$(this).css("height", maxHeight);   // Set new height
			$(this).css("width", width * ratio);    // Scale width based on ratio
			width = width * ratio;    // Reset width to match scaled image
		}

			$(this).load(function(){


				var width = $(this).width();    // Current image width
				var height = $(this).height();  // Current image height
				
				// Check if the current width is larger than the max
				if(width > maxWidth){
					ratio = maxWidth / width;   // get ratio for scaling image
					$(this).css("width", maxWidth); // Set new width
					$(this).css("height", height * ratio);  // Scale height based on ratio
					height = height * ratio;    // Reset height to match scaled image
					width = width * ratio;    // Reset width to match scaled image
				}
		 
				// Check if current height is larger than max
				if(height > maxHeight){
					ratio = maxHeight / height; // get ratio for scaling image
					$(this).css("height", maxHeight);   // Set new height
					$(this).css("width", width * ratio);    // Scale width based on ratio
					width = width * ratio;    // Reset width to match scaled image
				}

				parent.find('.loading').remove();	
				$(this).show();
			});
			
			
			
			
		
		if($.browser.msie)
		{
		$(this).wrap('<table onclick="self.location.href=\''+href+'\'" border="0" cellpadding="0" cellspacing="0" width="122" height="122">'
					 +'<tr><td align="center" valign="middle" ></td></tr></table>');
		}
		else
		{$(this).wrap('<table border="0" cellpadding="0" cellspacing="0" width="122" height="122"><tr><td align="center" valign="middle" ></td></tr></table>');}
		
	});
	//FOR IE
	$(window).load(function(){$('.thumb_bg .loading').remove();$('.thumb_bg img').show(); });
});




$(document).ready(function() {
						 
	$('#detail_img img').each(function() {
									   $(this).hide();
		var maxWidth = 220; // Max width for the image
		var maxHeight = 250;    // 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
		
				if ($(this).width() >= $(this).height()){$(this).css("width", 220);}
				else{$(this).css("height", 250);}// Set new height



		$(this).load(function(){
			// Check if the current width is larger than the max
				if ($(this).width() >= $(this).height()){$(this).css("width", 220);}
				else{$(this).css("height", 250);}// Set new height
			$(this).show();
		});


		$(this).wrap('<table border="0" cellpadding="0" cellspacing="0" width="220"><tr><td align="center" valign="middle" ></td></tr></table>');
		//$(this).css({'display': 'block', 'z-index':'5'});
		
		
		
		//for IE
		$(window).load(function(){$('#detail_img img').show();});


	});
});



