var userAgent = window.navigator.userAgent.toLowerCase();
var browzaType = "other"
if (userAgent.indexOf('msie') != -1) {
	browzaType = "ie";
}

//$(document).ready(function(){
$(function(){
//$("body").ready(function(){
	setTimeout(function(){
		var changesmallSize = 50;
		var changeSize = 72;
		var changeProSize = 128;
	if ($("div").hasClass("prolist_osusume_niayou")) {
		var el = $("div.prolist_osusume_niayou");
		el.each(function(){
			
			var imgWidth = $(this).find("img").width();
			var imgHeight = $(this).find("img").height();

			if (imgWidth > changeSize || imgHeight > changeSize) {
				if (imgWidth >= imgHeight) {
					$(this).find("img").width(changeSize);
					changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
					if (changeAfterImgHeight < 72) {
						marginSpaceTop = Math.round((changeSize - changeAfterImgHeight)/2);
						$(this).find("img").css("margin-top", marginSpaceTop);
					}
				}
				else {
					$(this).find("img").height(changeSize);
					changeAfterImgWidth = Math.ceil($(this).find("img").width());
					if (changeAfterImgWidth%2 != 0) {
						changeAfterImgWidth = changeAfterImgWidth - 1;
					}
					$(this).find("img").width(changeAfterImgWidth);
				}
			}
			else {
				changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
				if (changeAfterImgHeight < 72) {
					marginSpaceTop = Math.round((changeSize - changeAfterImgHeight)/2);
					$(this).find("img").css("margin-top", marginSpaceTop);
				}
				
				changeAfterImgWidth = Math.ceil($(this).find("img").width());
				if (changeAfterImgWidth%2 != 0) {
					changeAfterImgWidth = changeAfterImgWidth - 1;
				}
				$(this).find("img").width(changeAfterImgWidth);
			}
		});
	}
	if ($("div").hasClass("prolist_main_img")) {
		var el2 = $("div.prolist_main_img");
		el2.each(function(){
			
			if (browzaType == "ie") {
				$(this).find("a").width(changeSize + 2);
				$(this).find("a").height(changeSize + 2);
			}

			var imgWidth = $(this).find("img").width();
			var imgHeight = $(this).find("img").height();

			if (imgWidth > changeSize || imgHeight > changeSize) {
				if (imgWidth >= imgHeight) {
					$(this).find("img").width(changeSize);
					changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
					if (changeAfterImgHeight < 72) {
						marginSpaceTop = Math.round((changeSize - changeAfterImgHeight)/2);
						$(this).find("img").css("margin-top", marginSpaceTop);
					}
				}
				else {
					$(this).find("img").height(changeSize);
					changeAfterImgWidth = Math.ceil($(this).find("img").width());
					if (changeAfterImgWidth%2 != 0) {
						changeAfterImgWidth = changeAfterImgWidth - 1;
					}
					$(this).find("img").width(changeAfterImgWidth);
				}
			}
			else {
				changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
				if (changeAfterImgHeight < 72) {
					marginSpaceTop = Math.round((changeSize - changeAfterImgHeight)/2);
					$(this).find("img").css("margin-top", marginSpaceTop);
				}
				
				changeAfterImgWidth = Math.ceil($(this).find("img").width());
				if (changeAfterImgWidth%2 != 0) {
					changeAfterImgWidth = changeAfterImgWidth - 1;
				}
				$(this).find("img").width(changeAfterImgWidth);
			}
		});
	}

	if ($("div").hasClass("profile_syoukai")) {
		var el3 = $("div.profile_syoukai");
		el3.each(function(){
			if (browzaType == "ie") {
				$(this).find("p").width(changeSize + 4);
				$(this).find("p").height(changeSize + 4);
				
			}
			var imgWidth = $(this).find("img").width();
			var imgHeight = $(this).find("img").height();

			if (imgWidth > changeSize || imgHeight > changeSize) {
				if (imgWidth >= imgHeight) {
					$(this).find("img").width(changeSize);
					changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
					if (changeAfterImgHeight < changeSize) {
						marginSpaceTop = Math.round((changeSize - changeAfterImgHeight)/2);
						$(this).find("img").css("margin-top", marginSpaceTop);
					}
				}
				else {
					$(this).find("img").height(changeSize);
					changeAfterImgWidth = Math.ceil($(this).find("img").width());
					if (changeAfterImgWidth%2 != 0) {
						changeAfterImgWidth = changeAfterImgWidth - 1;
					}
					$(this).find("img").width(changeAfterImgWidth);
				}
			}
			else {
				changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
				if (changeAfterImgHeight < changeSize) {
					marginSpaceTop = Math.round((changeSize - changeAfterImgHeight)/2);
					$(this).find("img").css("margin-top", marginSpaceTop);
				}
				
				changeAfterImgWidth = Math.ceil($(this).find("img").width());
				if (changeAfterImgWidth%2 != 0) {
					changeAfterImgWidth = changeAfterImgWidth - 1;
				}
				$(this).find("img").width(changeAfterImgWidth);
			}
		});
	}
	if ($("div").hasClass("syasinn")) {
		var el4 = $("div.syasinn");
		el4.each(function(){
			
			var imgWidth = $(this).find("img").width();
			var imgHeight = $(this).find("img").height();

			if (imgWidth > changeProSize || imgHeight > changeProSize) {
				if (imgWidth >= imgHeight) {
					$(this).find("img").width(changeProSize);
					changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
					if (changeAfterImgHeight < changeProSize) {
						marginSpaceTop = Math.round((changeProSize - changeAfterImgHeight)/2);
						$(this).find("img").css("margin-top", marginSpaceTop);
					}
				}
				else {
					$(this).find("img").height(changeProSize);
					changeAfterImgWidth = Math.ceil($(this).find("img").width());
					if (changeAfterImgWidth%2 != 0) {
						changeAfterImgWidth = changeAfterImgWidth - 1;
					}
					$(this).find("img").width(changeAfterImgWidth);
				}
			}
			else {
				changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
				if (changeAfterImgHeight < changeProSize) {
					marginSpaceTop = Math.round((changeProSize - changeAfterImgHeight)/2);
					$(this).find("img").css("margin-top", marginSpaceTop);
				}
				
				changeAfterImgWidth = Math.ceil($(this).find("img").width());
				if (changeAfterImgWidth%2 != 0) {
					changeAfterImgWidth = changeAfterImgWidth - 1;
				}
				$(this).find("img").width(changeAfterImgWidth);
				$(this).find("img").height(changeAfterImgHeight);
			}
		});
	}
	if ($("div").hasClass("bani-inner")) {	
		var el5 = $("div.bani-inner p.now");
		el5.each(function(){
			if (browzaType == "ie") {
				$(this).find("span.image_waku").width(changeProSize + 4);
				$(this).find("span.image_waku").height(changeProSize + 4);	
			}
			
			var imgWidth = $(this).find("img").width();
			var imgHeight = $(this).find("img").height();

			if (imgWidth > changeProSize || imgHeight > changeProSize) {
				if (imgWidth >= imgHeight) {
					$(this).find("img").width(changeProSize);
					changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
					if (changeAfterImgHeight < changeProSize) {
						marginSpaceTop = Math.round((changeProSize - changeAfterImgHeight)/2);
						$(this).find("img").css("margin-top", marginSpaceTop);
					}
				}
				else {
					$(this).find("img").height(changeProSize);
					changeAfterImgWidth = Math.ceil($(this).find("img").width());
					if (changeAfterImgWidth%2 != 0) {
						changeAfterImgWidth = changeAfterImgWidth - 1;
					}
					$(this).find("img").width(changeAfterImgWidth);
				}
			}
			else {
				changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
				if (changeAfterImgHeight < changeProSize) {
					marginSpaceTop = Math.round((changeProSize - changeAfterImgHeight)/2);
					$(this).find("img").css("margin-top", marginSpaceTop);
				}
				
				changeAfterImgWidth = Math.ceil($(this).find("img").width());
				if (changeAfterImgWidth%2 != 0) {
					changeAfterImgWidth = changeAfterImgWidth - 1;
				}
				$(this).find("img").width(changeAfterImgWidth);
				$(this).find("img").height(changeAfterImgHeight);
			}
		});
	}
	if ($("div").hasClass("banita_osusume")) {	
		var el6 = $(".banita_osusume_table td.td1");
		el6.each(function(){
			if (browzaType == "ie") {
				$(this).find("a").width(changesmallSize + 2);
				$(this).find("a").height(changesmallSize + 2);
				
			}
			var imgWidth = $(this).find("img").width();
			var imgHeight = $(this).find("img").height();

			if (imgWidth > changesmallSize || imgHeight > changesmallSize) {
				if (imgWidth >= imgHeight) {
					$(this).find("img").width(changesmallSize);
					changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
					if (changeAfterImgHeight < changesmallSize) {
						marginSpaceTop = Math.round((changesmallSize - changeAfterImgHeight)/2);

						$(this).find("img").css("margin-top", marginSpaceTop);
					}
				}
				else {
					$(this).find("img").height(changesmallSize);
					changeAfterImgWidth = Math.ceil($(this).find("img").width());
					if (changeAfterImgWidth%2 != 0) {
						changeAfterImgWidth = changeAfterImgWidth - 1;
					}
					$(this).find("img").width(changeAfterImgWidth);
				}
			}
			else {
				changeAfterImgHeight = $(this).find("img").height();
					if (changeAfterImgHeight%2 != 0) {
						changeAfterImgHeight = changeAfterImgHeight - 1;
						$(this).find("img").height(changeAfterImgHeight);
					}
				if (changeAfterImgHeight < changesmallSize) {
					marginSpaceTop = Math.round((changesmallSize - changeAfterImgHeight)/2);
					$(this).find("img").css("margin-top", marginSpaceTop);
				}
				
				changeAfterImgWidth = Math.ceil($(this).find("img").width());
				if (changeAfterImgWidth%2 != 0) {
					changeAfterImgWidth = changeAfterImgWidth - 1;
				}
				$(this).find("img").width(changeAfterImgWidth);
				$(this).find("img").height(changeAfterImgHeight);
			}
		});
	}

	},500);
});

function banitaImgchange() {

	var changeProSize = 128;
	var el7 = $("div.bani-inner p.now");
	el7.each(function(){
		if (browzaType == "ie") {
			$(this).find("span.image_waku").width(changeProSize + 4);
			$(this).find("span.image_waku").height(changeProSize + 4);
		}

		var imgWidth = $(this).find("img").width();
		var imgHeight = $(this).find("img").height();

		if (imgWidth > changeProSize || imgHeight > changeProSize) {
			if (imgWidth >= imgHeight) {
				$(this).find("img").width(changeProSize);
				changeAfterImgHeight = $(this).find("img").height();
				if (changeAfterImgHeight%2 != 0) {
					changeAfterImgHeight = changeAfterImgHeight - 1;
					$(this).find("img").height(changeAfterImgHeight);
				}
				if (changeAfterImgHeight < changeProSize) {
					marginSpaceTop = Math.round((changeProSize - changeAfterImgHeight)/2);
					$(this).find("img").css("margin-top", marginSpaceTop);
				}
			}
			else {
				$(this).find("img").height(changeProSize);
				changeAfterImgWidth = Math.ceil($(this).find("img").width());
				if (changeAfterImgWidth%2 != 0) {
					changeAfterImgWidth = changeAfterImgWidth - 1;
				}
				$(this).find("img").width(changeAfterImgWidth);
			}
		}
		else {
			changeAfterImgHeight = $(this).find("img").height();
			if (changeAfterImgHeight%2 != 0) {
				changeAfterImgHeight = changeAfterImgHeight - 1;
				$(this).find("img").height(changeAfterImgHeight);
			}
			if (changeAfterImgHeight < changeProSize) {
				marginSpaceTop = Math.round((changeProSize - changeAfterImgHeight)/2);
				$(this).find("img").css("margin-top", marginSpaceTop);
			}
			
			changeAfterImgWidth = Math.ceil($(this).find("img").width());
			if (changeAfterImgWidth%2 != 0) {
				changeAfterImgWidth = changeAfterImgWidth - 1;
			}
			$(this).find("img").width(changeAfterImgWidth);
			$(this).find("img").height(changeAfterImgHeight);
		}
	});
}
