//フロント共通js
//dovument高速化
/*@cc_on _d=document;eval('var document=_d')@*/

//スクロールで関数起動(onScrollは準拠モードでは動かない)
window.onscroll = contactMove;

//----------------------------------------------汎用----------------------------------------------//

//className2であればclassName1に、そうでなければclassName1に変更
//二つのクラスをひとつのボタンで切り替えたりする場合に使用
function switchClass (targetObj, className1, className2) {
	if (className2 == false) {
		targetObj.className = className1;
	} else {
		if (targetObj.className == className1) {
			targetObj.className = className2;
		} else {
			targetObj.className = className1;
		}
	}
}

//classNameを切り替える
function changeClass (targetObj, className) {
	targetObj.className = className;
}

//指定された連番を含むIDすべてのchecked状態を第二引数の値に変更する
function allChkChange (targetId, value) {
	for (var i = 1; document.getElementById(targetId + String(i)); i++) {
		document.getElementById(targetId + String(i)).checked = value;
	}
}

//----------------------------------------------全般----------------------------------------------//

//お問い合わせボックススクロール
function contactMove() {
	if (document.getElementById('contactBox')) {
		//標準位置
		var defaultPos = -75;

		//上下スクロール幅を取得
		if (document.all) {
			if (typeof document.body.style.maxHeight != "undefined") {
				// IE 7, mozilla, safari, opera 9
				var scrollPoint = document.documentElement.scrollTop;	
			} else {
				// IE6, older browsers
				var scrollPoint = document.body.scrollTop;
			}
		} else {
			var scrollPoint = window.scrollY;
		}
		var topPos = defaultPos + scrollPoint;
		document.getElementById('contactBox').style.top = String(topPos) + 'px';
	}
}

//上部検索ボックス
function headSearchBox() {
	if (document.getElementById('headSearch').value == '物件名で検索できます') {
		document.getElementById('headSearch').value = '';
	} else if (document.getElementById('headSearch').value == '') {
		document.getElementById('headSearch').value = '物件名で検索できます';
	}
}

//----------------------------------------------index----------------------------------------------//

//エリアマップ
//PreLoad
function areaMapLoad () {
	areaImgAry = new Array(
		new Image(), new Image(), new Image(), new Image(), new Image(), 
		new Image(), new Image(), new Image(), new Image(), new Image(), 
		new Image(), new Image(), new Image(), new Image(), new Image(), 
		new Image(), new Image(), new Image(), new Image(), new Image(), 
		new Image(), new Image(), new Image(), new Image(), new Image(), 
		new Image(), new Image()
	);
	areaImgAry[0].src = '../images/index_area_map_roll_kita.jpg';
	areaImgAry[1].src = '../images/index_area_map_roll_chuo.jpg';
	areaImgAry[2].src = '../images/index_area_map_roll_nishi.jpg';
	areaImgAry[3].src = '../images/index_area_map_roll_yodogawa.jpg';
	areaImgAry[4].src = '../images/index_area_map_roll_higashiyodogawa.jpg';
	areaImgAry[5].src = '../images/index_area_map_roll_fukushima.jpg';
	areaImgAry[6].src = '../images/index_area_map_roll_naniwa.jpg';
	areaImgAry[7].src = '../images/index_area_map_roll_tennoji.jpg';
	areaImgAry[8].src = '../images/index_area_map_roll_miyakojima.jpg';
	areaImgAry[9].src = '../images/index_area_map_roll_suita.jpg';

	areaImgAry[10].src = '../images/index_area_map_kita_nakatsu.jpg';
	areaImgAry[11].src = '../images/index_area_map_kita_ten6.jpg';
	areaImgAry[12].src = '../images/index_area_map_kita_umeda.jpg';
	areaImgAry[13].src = '../images/index_area_map_kita_tenma.jpg';
	areaImgAry[14].src = '../images/index_area_map_kita_dojima.jpg';

	areaImgAry[15].src = '../images/index_area_map_chuo_yodoyabashi.jpg';
	areaImgAry[16].src = '../images/index_area_map_chuo_tenma.jpg';
	areaImgAry[17].src = '../images/index_area_map_chuo_honmachi.jpg';
	areaImgAry[18].src = '../images/index_area_map_chuo_tanimachi.jpg';
	areaImgAry[19].src = '../images/index_area_map_chuo_shinsaibashi.jpg';

	areaImgAry[20].src = '../images/index_area_map_nishi_awaza.jpg';
	areaImgAry[21].src = '../images/index_area_map_nishi_higobashi.jpg';
	areaImgAry[22].src = '../images/index_area_map_nishi_nishihonmachi.jpg';
	areaImgAry[23].src = '../images/index_area_map_nishi_yotsubashi.jpg';

	areaImgAry[24].src = '../images/index_area_map_yodogawa_higashimikuni.jpg';
	areaImgAry[25].src = '../images/index_area_map_yodogawa_shinosaka.jpg';
	areaImgAry[26].src = '../images/index_area_map_yodogawa_juso.jpg';
}

//MouseAction
function areaMapChange (targetId, imgName) {
	document.getElementById(targetId).src = '../images/index_area_map' + imgName + '.jpg';
}

//路線選択から駅選択を生成
function stationSelect (selectedId, targetId, path) {
	var	httpRequest = createHttpRequest();
	try {
		httpRequest.open('POST', path + 'station_select.php', true);
		httpRequest.setRequestHeader("content-type", "application/x-www-form-urlencoded");
		httpRequest.onreadystatechange = function () {
			if (httpRequest.readyState == 4 && httpRequest.status == 200 && httpRequest.responseText) {
				document.getElementById(targetId).innerHTML = httpRequest.responseText;
			}
		}
		httpRequest.send('id=' + selectedId);
	} catch(e) {
		alert("request failed.(" + e + ")");
	}
}

//----------------------------------------------再検索ボックス----------------------------------------------//
//submit
function narrowSubmit () {
	if (document.getElementById('st_midou_honmachi').checked == true || document.getElementById('st_yotsubashi_honmachi').checked == true) {
		document.getElementById('st_chuo_honmachi').disabled = false;
	} else {
		document.getElementById('st_chuo_honmachi').disabled = true;
	}
}

//----------------------------------------------詳細----------------------------------------------//

//サブ画像高さ設定
function subImgHeightSet() {
	var heightArray = new Array();
	for (var i = 1; document.getElementById('subImg' + String(i)); i++) {
		heightArray.push(document.getElementById('subImg' + String(i)).offsetHeight);
	}
	var rowNum = Math.ceil((i - 1) / 3);
	var rowHeightArray = new Array();
	for (var i = 0; i < rowNum; i++) {
		var row1 = i * 3;
		if (heightArray[row1 + 1]) {
			var maxHeight = Math.max(heightArray[row1], heightArray[row1 + 1]);
			if (heightArray[row1 + 2]) {
				maxHeight = Math.max(maxHeight, heightArray[row1 + 2]);
			}
		} else {
			var maxHeight = heightArray[row1];
		}
		rowHeightArray.push(maxHeight);
	}
	for (var i = 1; document.getElementById('subImg' + String(i)); i++) {
		if (heightArray[i - 1] != rowHeightArray[Math.ceil((i / 3) - 1)]) {
			var imgHeight = document.getElementById('subImg' + String(i) + 'Img').offsetHeight;
			if (document.getElementById('subImg' + String(i) + 'Txt')) {
				var txtHeight = document.getElementById('subImg' + String(i) + 'Txt').offsetHeight + 10;
			} else {
				var txtHeight = 0;
			}
			var innerHeight  = imgHeight + txtHeight + 5; //固定値
			var marginHeight = Math.ceil((rowHeightArray[Math.ceil((i / 3) - 1)] - innerHeight) / 2);
			document.getElementById('subImg' + String(i) + 'Img').style.marginTop = String(marginHeight) + 'px';
		}
		document.getElementById('subImg' + String(i)).style.height = String(rowHeightArray[Math.ceil((i / 3) - 1)]) + 'px';
	}
}


//GoogleMaps
//日本標準座標に変換
function JPoint(a, b, mode) {
	if (mode == 'E') {
		var x = a - b * 0.000046038 - a * 0.000083043 + 0.010040;
		return x;
	} else {
		var y = b - b * 0.00010695 + a * 0.000017464 + 0.0046017;
		return y;
	}
}

//GoogleMapsAPI表示
function initialize(east, north) {
	var latlng = new google.maps.LatLng(JPoint(east, north, 'N'), JPoint(east, north, 'E'));
	var mapOpts = {
		zoom: 17,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		streetViewControl: false
	};
	var mapCanvas = new google.maps.Map(document.getElementById("gMap"), mapOpts);

	var markerOpts = {
		position: latlng,
		map: mapCanvas
	};
	var crossMarker = new google.maps.Marker(markerOpts);

	var panoOpts = {
		position: latlng
	};
	var mapCanvas = new google.maps.StreetViewPanorama(document.getElementById("gSV"), panoOpts);
}

//近い物件表示切替
function rcmWrt(key, page, area, price, size, hPick) {
	var	httpRequest = createHttpRequest();
	try {
		httpRequest.open('POST', '../script/view_recommend.php', true);
		httpRequest.setRequestHeader("content-type", "application/x-www-form-urlencoded");
		httpRequest.onreadystatechange = function () {
			if (httpRequest.readyState == 4 && httpRequest.status == 200 && httpRequest.responseText) {
				document.getElementById('viewRcm').innerHTML = httpRequest.responseText;

				//初期化
				sFlag  = true;
				startX = 0;
				pageMove();
			}
		}
		httpRequest.send('key_name=' + key + '&page=' + page + '&area_flag=' + area + '&price_flag=' + price + '&size_flag=' + size + '&hard_pick_flag=' + hPick);
	} catch(e) {
		alert("request failed.(" + e + ")");
	}
}

//----------------------------------------------ライトボックス----------------------------------------------//
//拡大表示
var BAlpha = 70;
var WAlpha = 30;
var IAlpha = 30;
var inflag7 = false;
var angle = 0;
function photoView(imgPath,width,height,keyName,allNum,thisNum) {
	//グローバル変数へ代入
	window.imgPath = imgPath; //画像パス
	window.width   = width;   //画像横幅
	window.height  = height;  //画像縦幅
	window.keyName = keyName; //keyName
	window.allNum  = allNum;  //全画像数
	window.thisNum = thisNum; //この画像の番号

	//グレーアウト処理
	document.getElementById('viewImgBase').className = 'viewImgBase';
	window.bodyWidth = 0;
	window.bodyHeight = 0;
	if (window.innerHeight && window.scrollMaxY) {	
		bodyWidth = window.innerWidth + window.scrollMaxX;
		bodyHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		bodyWidth = document.body.scrollWidth;
		bodyHeight = document.body.scrollHeight;
	} else {
		bodyWidth = document.body.offsetWidth;
		bodyHeight = document.body.offsetHeight;
	}
	document.getElementById('viewImgBase').style.width = bodyWidth + 'px';
	document.getElementById('viewImgBase').style.height = bodyHeight + 'px';
	baseAlpha();

	//bodyのサイズより画像サイズが大きければ縮小処理
	if (bodyWidth * 0.8 < width || bodyHeight * 0.8 < height) {
		var reSizePercentW = width / (bodyWidth * 0.8);
		var reSizePercentH = height / (bodyHeight * 0.8);
		if (reSizePercentW > reSizePercentH) {
			window.width = parseInt(bodyWidth * 0.8);
			window.height = parseInt(height / reSizePercentW);
		}
		if (reSizePercentW < reSizePercentH) {
			window.width = parseInt(width / reSizePercentH);
			window.height = parseInt(bodyHeight * 0.8);
		}
		if (reSizePercentW == reSizePercentH) {
			window.width = parseInt(bodyWidth * 0.8);
			window.height = parseInt(bodyHeight * 0.8);
		}
	}
}
function photoView2() {
	//画像白ベース出力
	window.imgMargin = 20;
	window.whiteWidth = width + imgMargin;
	window.whiteHeight = height + imgMargin;
	window.startX = bodyWidth / 2 - imgMargin;
	var startY = 100;

	if (document.all) {
		if (typeof document.body.style.maxHeight != "undefined") {
			// IE 7, mozilla, safari, opera 9
			var scrollPoint = document.documentElement.scrollTop;	
		} else {
			// IE6, older browsers
			var scrollPoint = document.body.scrollTop;
		}
	} else {
		var scrollPoint = window.scrollY;
	}
	startY += scrollPoint;

	document.getElementById('whiteBase').style.left = startX + 'px';
	document.getElementById('whiteBase').style.top = startY + 'px';
	document.getElementById('whiteBase').style.width = imgMargin * 2;
	document.getElementById('whiteBase').style.height = imgMargin * 2;
	whiteAlpha();
}
function photoView3() {
	//白ベースタテ伸ばし
	var WHeight = imgMargin * 2;
	WhiteHeight(WHeight,whiteHeight);
}
function photoView4() {
	//白ベースヨコ伸ばし
	var Wwidth = imgMargin * 2;
	WhiteWidth(Wwidth,whiteWidth);
}
function photoView5() {
	//実寸画像出力
	var leftRightMargin = imgMargin / 2;
	document.getElementById('whiteBase').innerHTML = '<img src="' + imgPath + '" width="' + width + '" height="' + height + '" id="imgLayer">';
	document.getElementById('imgLayer').style.left = leftRightMargin + 'px';
	document.getElementById('imgLayer').style.top = leftRightMargin + 'px';
	imgAlpha();
}
function photoView6() {
	//ボトム伸ばし
	window.lastWhiteHeight = whiteHeight + 30;
	bottomHeight(whiteHeight,lastWhiteHeight);

}
function photoView7() {
	//閉じるボタンとページ移動ボタンとコメント出力
	if (inflag7 == false) {
		var commentStr = getComment(imgPath);
		document.getElementById('whiteBase').innerHTML += '<div id="closeButton" onClick="closeImg();"><span class="close">CLOSE</span><span class="batsu">×</span></div>';
		document.getElementById('whiteBase').innerHTML += '<div id="numViewBox">Image ' + thisNum + ' of ' + allNum + '</div>';
		document.getElementById('whiteBase').innerHTML += '<div id="commentBox">' + commentStr + '</div>';
		if (thisNum != 1) {
			var backTagStr = '<div id="backButtonBase" onMouseOver="document.getElementById(\'backButton\').className=\'roll\';" ';
			backTagStr += 'onMouseOut="document.getElementById(\'backButton\').className=\'\';" onClick="backView(\'' + keyName + '\',' + thisNum + ');"><div id="backButton">BACK</div></div>';
			document.getElementById('whiteBase').innerHTML += backTagStr;
			var backButtonLeft = imgMargin / 2;
			var backButtonTop = imgMargin / 2;
			var halfWidth = width / 2 - 2;
			document.getElementById('backButtonBase').style.left = backButtonLeft + 'px';
			document.getElementById('backButtonBase').style.top = backButtonTop + 'px';
			document.getElementById('backButtonBase').style.width = halfWidth + 'px';
			document.getElementById('backButtonBase').style.height = height + 'px';
			document.getElementById('backButtonBase').style.backgroundImage = 'url(../images/space.gif)';
			document.getElementById('backButtonBase').style.filter = 'alpha(opacity=100)';
			document.getElementById('backButtonBase').style.MozOpacity = 1;
			document.getElementById('backButtonBase').style.opacity = 1;
			document.getElementById('backButton').style.left = '0px';
			document.getElementById('backButton').style.top = '20%';
		}
		if (thisNum != allNum) {
			var nextTagStr = '<div id="nextButtonBase" onMouseOver="document.getElementById(\'nextButton\').className=\'roll\';" ';
			nextTagStr += 'onMouseOut="document.getElementById(\'nextButton\').className=\'\';" onClick="nextView(\'' + keyName + '\',' + thisNum + ');"><div id="nextButton">NEXT</div></div>';
			document.getElementById('whiteBase').innerHTML += nextTagStr;
			var nextButtonLeft = width / 2 + imgMargin / 2 + 2;
			var nextButtonTop = imgMargin / 2;
			var halfWidth = width / 2 - 2;
			var nextButtonNameW = halfWidth - 50;
			document.getElementById('nextButtonBase').style.left = nextButtonLeft + 'px';
			document.getElementById('nextButtonBase').style.top = nextButtonTop + 'px';
			document.getElementById('nextButtonBase').style.width = halfWidth + 'px';
			document.getElementById('nextButtonBase').style.height = height + 'px';
			document.getElementById('nextButtonBase').style.backgroundImage = 'url(../images/space.gif)';
			document.getElementById('nextButtonBase').style.filter = 'alpha(opacity=100)';
			document.getElementById('nextButtonBase').style.MozOpacity = 1;
			document.getElementById('nextButtonBase').style.opacity = 1;
			document.getElementById('nextButton').style.left = nextButtonNameW + 'px';
			document.getElementById('nextButton').style.top = '20%';
		}
		inflag7 = true;
	}
	var buttonLeft = whiteWidth - 90;
	var buttonTop = whiteHeight - 6;
	document.getElementById('closeButton').style.left = buttonLeft + 'px';
	document.getElementById('closeButton').style.top = buttonTop + 'px';
	document.getElementById('closeButton').style.visibility = 'visible';
	var numViewLeft = imgMargin / 2 + 2;
	var numViewTop = whiteHeight + 5;
	document.getElementById('numViewBox').style.left = numViewLeft + 'px';
	document.getElementById('numViewBox').style.top = numViewTop + 'px';
	document.getElementById('numViewBox').style.visibility = 'visible';
	var commentLeft = imgMargin / 2;
	var commentTop = whiteHeight - 6 + 34;
	document.getElementById('commentBox').style.left = commentLeft + 'px';
	document.getElementById('commentBox').style.top = commentTop + 'px';
	window.commentH = document.getElementById('commentBox').offsetHeight + lastWhiteHeight + 5;
	commentHeight(lastWhiteHeight,commentH);
}
function photoView8() {
	//コメント表示
	document.getElementById('commentBox').style.visibility = 'visible';
	if (thisNum != 1) {
		document.getElementById('backButtonBase').style.visibility = 'visible';
	}
	if (thisNum != allNum) {
		document.getElementById('nextButtonBase').style.visibility = 'visible';
	}
	commentShadow();
}

//拡大画像表示用モーション関数群
function baseAlpha() {
	BAlpha = BAlpha + 2;
	if (BAlpha <= 86) {
		document.getElementById('viewImgBase').style.filter = 'alpha(opacity=' + BAlpha + ')';
		document.getElementById('viewImgBase').style.MozOpacity = BAlpha / 100 - 0.1;
		document.getElementById('viewImgBase').style.opacity = BAlpha / 100 - 0.1;
		setTimeout('baseAlpha()', 5);
		BAlpha = BAlpha + 2;
		document.getElementById('viewImgBase').style.filter = 'alpha(opacity=' + BAlpha + ')';
		document.getElementById('viewImgBase').style.MozOpacity = BAlpha / 100 - 0.1;
		document.getElementById('viewImgBase').style.opacity = BAlpha / 100 - 0.1;
		setTimeout('baseAlpha()', 5);
	} else {
		photoView2();
	}
}
function whiteAlpha() {
	WAlpha = WAlpha + 2;
	if (WAlpha < 99) {
		document.getElementById('whiteBase').style.filter = 'alpha(opacity=' + WAlpha + ')';
		document.getElementById('whiteBase').style.MozOpacity = WAlpha / 100 - 0.1;
		document.getElementById('whiteBase').style.opacity = WAlpha / 100 - 0.1;
		setTimeout('whiteAlpha()', 5);
		WAlpha = WAlpha + 2;
		document.getElementById('whiteBase').style.filter = 'alpha(opacity=' + WAlpha + ')';
		document.getElementById('whiteBase').style.MozOpacity = WAlpha / 100 - 0.1;
		document.getElementById('whiteBase').style.opacity = WAlpha / 100 - 0.1;
		setTimeout('whiteAlpha()', 5);
	} else {
		document.getElementById('whiteBase').style.filter = 'alpha(opacity=100)';
		document.getElementById('whiteBase').style.MozOpacity = 1;
		document.getElementById('whiteBase').style.opacity = 1;
		photoView3();
	}
}
function WhiteHeight(px,maxHeight) {
	px = px + 20;
	if (px <= maxHeight) {
		document.getElementById('whiteBase').style.height = px + 'px';
		setTimeout('WhiteHeight(' + px + ',' + maxHeight + ')', 5);
	} else {
		document.getElementById('whiteBase').style.height = maxHeight + 'px';
		photoView4();
	}
}
function WhiteWidth(px,maxWidth) {
	px = px + 20;
	if (px <= maxWidth) {
		var moveToLeft = startX - px / 2;
		document.getElementById('whiteBase').style.width = px + 'px';
		document.getElementById('whiteBase').style.left = moveToLeft + 'px';
		setTimeout('WhiteWidth(' + px + ',' + maxWidth + ')', 5);
	} else {
		var moveToLeft = startX - maxWidth / 2;
		document.getElementById('whiteBase').style.width = maxWidth + 'px';
		document.getElementById('whiteBase').style.left = moveToLeft + 'px';
		photoView5();
	}
}
function imgAlpha() {
	IAlpha = IAlpha + 2;
	if (IAlpha < 99) {
		document.getElementById('imgLayer').style.filter = 'alpha(opacity=' + IAlpha + ')';
		document.getElementById('imgLayer').style.MozOpacity = IAlpha / 100 - 0.1;
		document.getElementById('imgLayer').style.opacity = IAlpha / 100 - 0.1;
		setTimeout('imgAlpha()', 5);
		IAlpha = IAlpha + 2;
		document.getElementById('imgLayer').style.filter = 'alpha(opacity=' + IAlpha + ')';
		document.getElementById('imgLayer').style.MozOpacity = IAlpha / 100 - 0.1;
		document.getElementById('imgLayer').style.opacity = IAlpha / 100 - 0.1;
		setTimeout('imgAlpha()', 5);
	} else {
		document.getElementById('imgLayer').style.filter = 'alpha(opacity=100)';
		document.getElementById('imgLayer').style.MozOpacity = 1;
		document.getElementById('imgLayer').style.opacity = 1;
		photoView6();
	}

}
function bottomHeight(px,maxHeight) {
	px = px + 10;
	if (px <= maxHeight) {
		document.getElementById('whiteBase').style.height = px + 'px';
		setTimeout('bottomHeight(' + px + ',' + maxHeight + ')', 5);
	} else {
		document.getElementById('whiteBase').style.height = maxHeight + 'px';
		photoView7();
	}
}
function commentHeight(px,maxHeight) {
	px = px + 10;
	if (px <= maxHeight) {
		document.getElementById('whiteBase').style.height = px + 'px';
		setTimeout('commentHeight(' + px + ',' + maxHeight + ')', 5);
	} else {
		document.getElementById('whiteBase').style.height = maxHeight + 'px';
		photoView8();
	}
}
function commentShadow() {
	angle = angle + 1;
	if (angle <= 135) {
		document.getElementById('commentBox').style.filter = 'shadow(color=#CCCCDD, direction=' + angle + ')';
		setTimeout('commentShadow()', 20);
	} else {
		document.getElementById('commentBox').style.filter = 'shadow(color=#CCCCDD, direction=135)';
	}
}

//BACK表示
function backView(keyName,thisNum) {
	if (thisNum != 1) {
		document.getElementById('backButtonBase').style.visibility = 'hidden';
	}
	if (thisNum != allNum) {
		document.getElementById('nextButtonBase').style.visibility = 'hidden';
	}
	window.reResultStr = getBackImg(keyName,thisNum);
	document.getElementById('whiteBase').innerHTML = '&nbsp;';
	turnWhiteHeight(commentH,whiteHeight);
}

//NEXT表示
function nextView(keyName,thisNum) {
	if (thisNum != 1) {
		document.getElementById('backButtonBase').style.visibility = 'hidden';
	}
	if (thisNum != allNum) {
		document.getElementById('nextButtonBase').style.visibility = 'hidden';
	}
	window.reResultStr = getNextImg(keyName,thisNum);
	document.getElementById('whiteBase').innerHTML = '&nbsp;';
	turnWhiteHeight(commentH,whiteHeight);
}

//BACK・NEXT共通処理
function reView2() {
	reResultArray = reResultStr.split('<>');
	window.imgPath = reResultArray[0];
	window.width   = parseInt(reResultArray[1]);
	window.height  = parseInt(reResultArray[2]);
	window.thisNum = parseInt(reResultArray[3]);

	//bodyのサイズより画像サイズが大きければ縮小処理
	if (bodyWidth * 0.8 < width || bodyHeight * 0.8 < height) {
		var reSizePercentW = width / (bodyWidth * 0.8);
		var reSizePercentH = height / (bodyHeight * 0.8);
		if (reSizePercentW > reSizePercentH) {
			window.width = parseInt(bodyWidth * 0.8);
			window.height = parseInt(height / reSizePercentW);
		}
		if (reSizePercentW < reSizePercentH) {
			window.width = parseInt(width / reSizePercentH);
			window.height = parseInt(bodyHeight * 0.8);
		}
		if (reSizePercentW == reSizePercentH) {
			window.width = parseInt(bodyWidth * 0.8);
			window.height = parseInt(bodyHeight * 0.8);
		}
	}

	window.oldWhiteWidth = whiteWidth;
	window.oldWhiteHeight = whiteHeight;
	window.whiteWidth = width + imgMargin;
	window.whiteHeight = height + imgMargin;
	reSizeWhiteW(oldWhiteWidth,whiteWidth);
}
function reView3() {
	window.BAlpha = 70;
	window.WAlpha = 30;
	window.IAlpha = 30;
	window.inflag7 = false;
	window.angle = 0;
	reSizeWhiteH(oldWhiteHeight,whiteHeight);
}

//BACK・NEXT表示用モーション関数群
function turnWhiteHeight(px,maxHeight) {
	px = px - 20;
	if (px >= maxHeight) {
		document.getElementById('whiteBase').style.height = px + 'px';
		setTimeout('turnWhiteHeight(' + px + ',' + maxHeight + ')', 5);
	} else {
		document.getElementById('whiteBase').style.height = maxHeight + 'px';
		reView2();
	}
}
function reSizeWhiteW(oldW,newW) {
	if (oldW < newW) {
		oldW = oldW + 20;
		if (oldW <= newW) {
			var moveToLeft = startX - oldW / 2;
			document.getElementById('whiteBase').style.width = oldW + 'px';
			document.getElementById('whiteBase').style.left = moveToLeft + 'px';
			setTimeout('reSizeWhiteW(' + oldW + ',' + newW + ')', 5);
		} else {
			var moveToLeft = startX - newW / 2;
			document.getElementById('whiteBase').style.width = newW + 'px';
			document.getElementById('whiteBase').style.left = moveToLeft + 'px';
			reView3();
		}
	}
	if (oldW > newW) {
		oldW = oldW - 20;
		if (oldW >= newW) {
			var moveToLeft = startX - oldW / 2;
			document.getElementById('whiteBase').style.width = oldW + 'px';
			document.getElementById('whiteBase').style.left = moveToLeft + 'px';
			setTimeout('reSizeWhiteW(' + oldW + ',' + newW + ')', 5);
		} else {
			var moveToLeft = startX - newW / 2;
			document.getElementById('whiteBase').style.width = newW + 'px';
			document.getElementById('whiteBase').style.left = moveToLeft + 'px';
			reView3();
		}
	}
	if (oldW == newW) {
		reView3();
	}
}
function reSizeWhiteH(oldH,newH) {

	if (oldH < newH) {
		oldH = oldH + 20;
		if (oldH <= newH) {
			document.getElementById('whiteBase').style.height = oldH + 'px';
			setTimeout('reSizeWhiteH(' + oldH + ',' + newH + ')', 5);
		} else {
			document.getElementById('whiteBase').style.height = newH + 'px';
			photoView5();
		}
	}
	if (oldH > newH) {
		oldH = oldH - 20;
		if (oldH >= newH) {
			document.getElementById('whiteBase').style.height = oldH + 'px';
			setTimeout('reSizeWhiteH(' + oldH + ',' + newH + ')', 5);
		} else {
			document.getElementById('whiteBase').style.height = newH + 'px';
			photoView5();
		}
	}
	if (oldH == newH) {
		photoView5();
	}
}

//閉じる処理
function closeImg() {
	window.BAlpha = 70;
	window.WAlpha = 30;
	window.IAlpha = 30;
	window.inflag7 = false;
	window.angle = 0;
	if (thisNum != 1) {
		document.getElementById('backButtonBase').style.visibility = 'hidden';
	}
	if (thisNum != allNum) {
		document.getElementById('nextButtonBase').style.visibility = 'hidden';
	}
	document.getElementById('commentBox').style.visibility = 'hidden';
	document.getElementById('numViewBox').style.visibility = 'hidden';
	document.getElementById('closeButton').style.visibility = 'hidden';
	document.getElementById('imgLayer').style.width = '0px';
	document.getElementById('imgLayer').style.height = '0px';
	document.getElementById('imgLayer').style.filter = 'alpha(opacity=0)';
	document.getElementById('imgLayer').style.MozOpacity = 0;
	document.getElementById('imgLayer').style.opacity = 0;
	widthClose(whiteWidth);
}
function closeImg2() {
	heightClose(whiteHeight);
}
function closeImg3() {
	document.getElementById('whiteBase').style.filter = 'alpha(opacity=0)';
	document.getElementById('whiteBase').style.MozOpacity = 0;
	document.getElementById('whiteBase').style.opacity = 0;
	document.getElementById('whiteBase').style.width = '0px';
	document.getElementById('whiteBase').style.height = '0px';
	document.getElementById('whiteBase').innerHTML = '&nbsp;';
	closeAlpha(70);
}
function closeImg4() {
	document.getElementById('viewImgBase').style.filter = 'alpha(opacity=70)';
	document.getElementById('viewImgBase').style.MozOpacity = 0.6;
	document.getElementById('viewImgBase').style.opacity = 0.6;
	document.getElementById('viewImgBase').className = '';
	var objectTag = document.getElementsByTagName('object');
	for (var i = 0; i < objectTag.length; i++) {
		objectTag[i].style.visibility = 'visible';
	}
}

function widthClose(closeWidth) {
	closeWidth = closeWidth - 60;
	if (closeWidth >= imgMargin * 2) {
		var moveToLeft = startX - closeWidth / 2;
		document.getElementById('whiteBase').style.width = closeWidth + 'px';
		document.getElementById('whiteBase').style.left = moveToLeft + 'px';
		setTimeout('widthClose(' + closeWidth + ')', 5);
	} else {
		var moveToLeft = startX - closeWidth / 2;
		document.getElementById('whiteBase').style.width = imgMargin * 2 + 'px';
		document.getElementById('whiteBase').style.left = moveToLeft + 'px';
		closeImg2();
	}
}
function heightClose(closeHeight) {
	closeHeight = closeHeight - 60;
	if (closeHeight >= 0) {
		document.getElementById('whiteBase').style.height = closeHeight + 'px';
		setTimeout('heightClose(' + closeHeight + ')', 5);
	} else {
		document.getElementById('whiteBase').style.height = '0px';
		closeImg3();
	}
}
function closeAlpha(closeAlpha) {
	closeAlpha = closeAlpha - 40;
	if (closeAlpha >= 0) {
		document.getElementById('viewImgBase').style.filter = 'alpha(opacity=' + closeAlpha + ')';
		document.getElementById('viewImgBase').style.MozOpacity = closeAlpha / 100 - 0.1;
		document.getElementById('viewImgBase').style.opacity = closeAlpha / 100 - 0.1;
		setTimeout('closeAlpha(' + closeAlpha + ')', 5);
	} else {
		document.getElementById('viewImgBase').style.filter = 'alpha(opacity=0)';
		document.getElementById('viewImgBase').style.MozOpacity = 0;
		document.getElementById('viewImgBase').style.opacity = 0;
		closeImg4();
	}
}


//非同期通信
function getComment(imagePath) {
	var	httpRequest = createHttpRequest();
	try {
		httpRequest.open('POST', '../script/view_light_box.php', false);
		httpRequest.setRequestHeader("content-type", "application/x-www-form-urlencoded");
		httpRequest.send('mode=getComment&path=' + imagePath);
		return httpRequest.responseText;
	} catch(e) {
		alert("request failed.(" + e + ")");
	}
}
function getBackImg(keyName,thisNum) {
	var	httpRequest = createHttpRequest();
	try {
		httpRequest.open('POST', '../script/view_light_box.php', false);
		httpRequest.setRequestHeader("content-type", "application/x-www-form-urlencoded");
		httpRequest.send('mode=getBackImg&key_name=' + keyName + '&this_num=' + thisNum);
		return httpRequest.responseText;
	} catch(e) {
		alert("request failed.(" + e + ")");
	}
}
function getNextImg(keyName,thisNum) {
	var	httpRequest = createHttpRequest();
	try {
		httpRequest.open('POST', '../script/view_light_box.php', false);
		httpRequest.setRequestHeader("content-type", "application/x-www-form-urlencoded");
		httpRequest.send('mode=getNextImg&key_name=' + keyName + '&this_num=' + thisNum);
		return httpRequest.responseText;
	} catch(e) {
		alert("request failed.(" + e + ")");
	}
}

