//フロント共通js

//トップページ 特集高さ揃えが起動したかどうか
featHeightFlag = false;

//フォントサイズCSS切替
function changeFont (type) {
	if (type == 1) {
		document.getElementById('container').className = 'large';
	} else {
		document.getElementById('container').className = 'normal';
	}
	if (featHeightFlag = true) {
		featHeightSet();
	}
}

//ヘッダ検索対象開く
function searchKindOn () {
	if (document.getElementById('searchKindBox').className == 'searchKindBoxOff') {
		document.getElementById('searchKindBox').className = 'searchKindBoxOn';
	} else {
		document.getElementById('searchKindBox').className = 'searchKindBoxOff';
	}
}

//ヘッダ検索対象選択
function selectSearchKind (kind_1, kind_2, name) {
	document.getElementById('searchKind1').value       = kind_1;
	document.getElementById('searchKind2').value       = kind_2;
	document.getElementById('searchKindBtn').innerHTML = name;
	searchKindOn();
}

//ヘッダ検索ボックス文字消去
function searchBoxVanish (obj) {
	if (obj.value == '物件名検索') {
		obj.value = '';
	} else if (obj.value == '') {
		obj.value = '物件名検索';
	}
}

//左 路線開閉
function stepOpenClose (id) {
	if (document.getElementById(id).className == 'bt6') {
		document.getElementById(id).className = 'bt7'
	} else {
		document.getElementById(id).className = 'bt6'
	}
}

//トップページ 特集高さ揃え
function featHeightSet () {
	var height_1 = document.getElementById('featInfo1').offsetHeight;
	var height_2 = document.getElementById('featInfo2').offsetHeight;
	if (document.getElementById('featInfo3')) {
		var height_3 = document.getElementById('featInfo3').offsetHeight;
	}

	var maxHeight = Math.max(height_1, height_2);
	if (document.getElementById('featInfo3')) {
		maxHeight = Math.max(maxHeight, height_3);
	}

	document.getElementById('featInfo1').style.height = String(maxHeight) + 'px';
	document.getElementById('featInfo2').style.height = String(maxHeight) + 'px';
	if (document.getElementById('featInfo3')) {
		document.getElementById('featInfo3').style.height = String(maxHeight) + 'px';
	}

	featHeightFlag = true;
}

//物件種類選択から物件種別選択を生成
function kindSelect (kind_1_id, targetId, targetId2) {
	var	httpRequest = createHttpRequest();
	try {
		httpRequest.open('POST', '../script/kind_select_1.php', true);
		httpRequest.setRequestHeader("content-type", "application/x-www-form-urlencoded");
		httpRequest.onreadystatechange = function () {
			if (httpRequest.readyState == 4 && httpRequest.status == 200 && httpRequest.responseText) {
				txtArray = httpRequest.responseText.split('<>');
				document.getElementById(targetId).innerHTML  = txtArray[0];

				if (targetId2 != '') {
					//kind_3選択もある場合
					document.getElementById(targetId2).innerHTML = txtArray[1];
				}
			}
		}
		if (targetId2 != '') {
			//kind_3選択もある場合
			httpRequest.send('kind_1=' + kind_1_id + '&mode=3');
		} else {
			httpRequest.send('kind_1=' + kind_1_id + '&mode=2');
		}
	} catch(e) {
		alert("request failed.(" + e + ")");
	}
}

//検索 都道府県選択から市区町村選択を生成
function citySelect (prefectureId, targetId) {
	var	httpRequest = createHttpRequest();
	try {
		httpRequest.open('POST', '../script/city_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('prefecture=' + prefectureId);
	} catch(e) {
		alert("request failed.(" + e + ")");
	}
}

//路線選択から駅選択を生成
function stationSelect (selectedId, targetId) {
	var	httpRequest = createHttpRequest();
	try {
		httpRequest.open('POST', '../script/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 + ")");
	}
}

//検索 チェックボックスを全てONにする
function allChecked () {
	for (buffer01 = 1; document.getElementById('equip_' + buffer01 + '_num'); buffer01++) {
		document.getElementById('equip_' + buffer01 + '_num').checked = true;
	}
	for (buffer01 = 1; document.getElementById('hard_pick_' + buffer01 + '_num'); buffer01++) {
		document.getElementById('hard_pick_' + buffer01 + '_num').checked = true;
	}
}

//検索 チェックボックスを全てOFFにする
function allUnchecked () {
	for (buffer01 = 1; document.getElementById('equip_' + buffer01 + '_num'); buffer01++) {
		document.getElementById('equip_' + buffer01 + '_num').checked = false;
	}
	for (buffer01 = 1; document.getElementById('hard_pick_' + buffer01 + '_num'); buffer01++) {
		document.getElementById('hard_pick_' + buffer01 + '_num').checked = false;
	}
}

//お気に入り追加(IE)
function addBookmarkIE (url, title) {
	window.external.AddFavorite(url,title);
}

//お気に入り追加(FF)
function addBookmarkFF (url, title) {
	window.sidebar.addPanel(title,url,'');
}

//日本標準座標に変換
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;
	}
}

//GoogleMapAPI表示
function initialize(east, north) {

	if(GBrowserIsCompatible()){


		//新仕様
		if (document.getElementById('gMap')) {
			//地図を作成
			var mapPos = new GLatLng(JPoint(east, north, 'N'), JPoint(east, north, 'E'));
			var map = new GMap2(document.getElementById('gMap'));
			var mapTypeCtrl = new GMapTypeControl();
			map.addControl(new GLargeMapControl());
			map.setCenter(mapPos, 17);
			map.enableDoubleClickZoom();
	
			//マップオーバービューコントローラを付ける
//			var miniMap = new GOverviewMapControl(new GSize(200, 150));
//			map.addControl(miniMap);
	
			//スケールコントローラ（尺度定規）を付ける
			map.addControl(new GScaleControl());
	
			//中心座標にマーカーを表示（衛星写真）
			var marker = new GMarker(mapPos);
			GEvent.addListener(marker, "click", function() {
				map.removeMapType(G_PHYSICAL_MAP);
				map.removeMapType(G_SATELLITE_3D_MAP);
				map.showMapBlowup(marker.getPoint(), {zoomLevel:18, mapType:G_SATELLITE_MAP, pixelOffset:new GSize(0, -20)});
				map.removeControl(mapTypeCtrl);
				map.addControl(mapTypeCtrl);
			});
			map.addOverlay(marker);
	
			//GoogleStreetView
			var pano = new GStreetviewPanorama(document.getElementById("gSV"), { latlng: mapPos});
		}




		//旧仕様
		if (document.getElementById('mapViewBox')) {
			var map = new GMap2(document.getElementById('mapViewBox'));
			var mapTypeCtrl = new GMapTypeControl();
			map.addControl(new GLargeMapControl());
			map.setCenter(mapPos, 17);
			map.enableDoubleClickZoom();
		
			//マップオーバービューコントローラを付ける
//			var miniMap = new GOverviewMapControl(new GSize(200, 150));
//			map.addControl(miniMap);
		
			//スケールコントローラ（尺度定規）を付ける
			map.addControl(new GScaleControl());
		
			//中心座標にマーカーを表示（衛星写真）
			var marker = new GMarker(mapPos);
			GEvent.addListener(marker, "click", function() {
				map.removeMapType(G_PHYSICAL_MAP);
				map.removeMapType(G_SATELLITE_3D_MAP);
				map.showMapBlowup(marker.getPoint(), {zoomLevel:18, mapType:G_SATELLITE_MAP, pixelOffset:new GSize(0, -20)});
				map.removeControl(mapTypeCtrl);
				map.addControl(mapTypeCtrl);
			});
			map.addOverlay(marker);
		}
	}
}

//お問い合わせ
//家族構成
function chkMarriage (id) {
	if (id == 1) {
		document.getElementById('marriage_1_select').disabled = false;
		document.getElementById('marriage_2_select').disabled = true;
	} else {
		document.getElementById('marriage_1_select').disabled = true;
		document.getElementById('marriage_2_select').disabled = false;
	}
}

//職業
function chkWork (id) {
	if (id == 1) {
		document.getElementById('work_kind').disabled = false;
		document.getElementById('work_other').disabled = true;
	} else if (id == 5) {
		document.getElementById('work_kind').disabled = true;
		document.getElementById('work_other').disabled = false;
	} else {
		document.getElementById('work_kind').disabled = true;
		document.getElementById('work_other').disabled = true;
	}
}

//近い物件表示切替
function rcmWrt (id, page, area, price, hPlan, hPick) {
//alert('id:' + id + ' page:' + page + ' area:' + area + ' prc:' + price + ' hPlan:' + hPlan + ' hPick:' + hPick);
	var	httpRequest = createHttpRequest();
	try {
		httpRequest.open('POST', './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;
			}
		}
		httpRequest.send('id=' + id + '&page=' + page + '&area_flag=' + area + '&price_flag=' + price + '&h_plan_flag=' + hPlan + '&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.whiteHeight = height + imgMargin + 20;
	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;
	var buttonTop = whiteHeight - 20;
	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 + ")");
	}
}
