$(window).load(function() {

	$('img.roomPhoto').each(function() {
		var img = $(this);
		var width = img.width();
		var height = img.height();
		var ratio = 0;

		// All images are squares; therefore, set both max width and height to the same value
		var maxWidth = width;
		var maxHeight = width;

		if(height > maxHeight){
			img.removeAttr("width")
				 .removeAttr("height");

			ratio = maxHeight / height;
			img.css("width", width * ratio)
				 .attr("width", width * ratio)
				 .css("height", maxHeight)
				 .attr("height", maxHeight);
		}

		img.attr('src',img.attr('src')); // Trigger onload event if image is cached

		// Set alignment for parent elements
		var parentEl = img.parent();
		if (parentEl.is("td"))
		{
			parentEl.css('text-align','center');
		}
		else if (parentEl.is("a"))
		{
			// photos in the photo slider module
			parentEl.parent().css('text-align','center');
		}
	});

});