$(document).ready(function(){
	imgSize();
});
function imgSize(){
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	$('.image').each(function(){
		var self = $(this);
		var objectImg = new Image();
		objectImg.onload = function(){
			$('.image').css('display','none');
			var height = objectImg.height;
			var width = objectImg.width;
			var parent = $(self).parent().parent();
			var maxHeight = $(parent).height()-2;
			var maxWidth = $(parent).width()-2;

			if (width>maxWidth){
				height = height/(width/maxWidth);
				width = maxWidth;
			}
			if (height>maxHeight){
				width = width/(height/maxHeight);
				height = maxHeight;
			}
			width=width.toFixed(0);
			height=height.toFixed(0);
			self.css({width:width+"px",height:height+"px"});

			var heightPadding = parseInt((maxHeight-height)/2);
			if((maxHeight-height)%2) self.css({paddingTop:(heightPadding+1)+"px"});
			else self.css({paddingTop:(heightPadding)+"px"});
			self.css({paddingBottom:(heightPadding)+"px"});

			var widthPadding = parseInt((maxWidth-width)/2);
			if((maxWidth-width)%2) self.css({paddingLeft:(widthPadding+1)+"px"});
			else self.css({paddingLeft:(widthPadding)+"px"});
			self.css({paddingRight:(widthPadding)+"px"});
			$('.image').css('display','');
		}
		objectImg.src = ($(this).attr('src'));
	});
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	$('#subContent img').each(function(){
		var self = $(this);
		var objectImg = new Image();
		objectImg.onload = function(){
			$('#subContent img').css('display','none');
			var this_height = $(self).height();
			var this_width = $(self).width();
			var height = objectImg.height;
			var width = objectImg.width;
			var parent = $(self).parent().parent();
			var maxWidth = $('#subContent').width();
			if(this_width > maxWidth){
				if (width>maxWidth){
					height = height/(width/maxWidth);
					width = maxWidth;
					if(!$(self).parent().hasClass('imageContainer')) $(self).wrap('<span class="imageContainer" style="text-align:center;display:block;"></span>');
				}
				width=width.toFixed(0);
				height=height.toFixed(0);
				self.css({width:width+"px",height:height+"px"});
			}
			$('#subContent img').css('display','');
		}
		objectImg.src = ($(this).attr('src'));
	});
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
