// ランキング表示数
var rankingCnt = 3;
window.onload = function() {
	preLoadImg('/user_data/packages/default/');
	var yoko_max_w	= 522;
	var yoko_max_h	= 396;
	var tate_max_w	= 480;
	var tate_max_h	= 640;
	var image;
	var key1;
	var key2;
	var key3;
	var myImg;
	var newimg;
	for (var j = 1; j <= rankingCnt; j++) {
		key1 = 'rollover_view' + j;
		key2 = 'thumb' + j;
		image = document.getElementById(key1);
		if (image.className === 'yokoimg') {
			slideResize(image, yoko_max_w, yoko_max_h, key1);
		} else if (image.className === 'tateimg') {
			slideResize(image, tate_max_w, tate_max_h, key1);
		}
		myImg = document.getElementById(key2).getElementsByTagName('img');
		newimg = new Array();
		for (var i = 0; i <myImg.length; i++) {
			newimg[i] = new Image();
			newimg[i].src = myImg[i].src;
			myImg[i].onmouseover = function() {
				if (this.id != '') {
					key3 = 'rollover_view' + this.id.substr(3,1);
				}
				if (this.className === 'yokoimg') {
					slideResize(this, yoko_max_w, yoko_max_h, key3);
					document.getElementById(key3).src = this.src;
				} else if (this.className === 'tateimg') {
					slideResize(this, tate_max_w, tate_max_h, key3);
					document.getElementById(key3).src = this.src;
				}
			}
		}
	}
}
function slideResize(image, max_w, max_h, target_id) {
	var w = image.naturalWidth;
	var h = image.naturalHeight;
	// Firefox, Safari, Chrome
	if (typeof image.naturalWidth !== 'undefined') {
		w = image.naturalWidth;
		h = image.naturalHeight;
	// IE
	} else if (typeof image.runtimeStyle !== 'undefined') {
		var run = image.runtimeStyle;
		// keep runtimeStyle
		var mem = {w: run.width, h: run.height};
		run.width  = 'auto';
		run.height = 'auto';
		w = image.width;
		h = image.height;
		run.width  = mem.w;
		run.height = mem.h;
	// Opera
	} else {
		// keep original style
		var mem = {w: image.width, h: image.height};
		image.removeAttribute('width');
		image.removeAttribute('height');
		w = image.width;
		h = image.height;
		image.width  = mem.w;
		image.height = mem.h;
	}
	// 画像サイズ調整
	if (w > max_w && h > max_h) {
		document.getElementById(target_id).width			= max_w;
		document.getElementById(target_id).height			= max_h;
		document.getElementById(target_id).style.marginTop	= 0;
	} else if (w > max_w) {
		document.getElementById(target_id).width			= max_w;
		document.getElementById(target_id).style.marginTop	= (max_h - h) / 2;
	} else if (h > max_h) {
		document.getElementById(target_id).height			= max_h;
		document.getElementById(target_id).style.marginTop	= 0;
	} else {
		document.getElementById(target_id).width			= w;
		document.getElementById(target_id).style.marginTop	= (max_h - h) / 2;
		document.getElementById(target_id).height			= h;
	}
	document.getElementById(target_id).src = image.src;
}
