
// 物件検索こだわり部分の表示非表示切替
function changeKodawari(){
	var cid = 'kodawari';
	var cid_i = 'kodawari_icon';
	if(document.all){
		obj = document.all(cid);
		obj_i = document.all(cid_i);
	}else if(document.getElementById){
		obj = document.getElementById(cid);
		obj_i = document.getElementById(cid_i);
	}
	if(obj.style.display == 'block'){
		obj.style.display = 'none';
		obj_i.src = '/img/kodawari_open.gif';
	}else{
		obj.style.display = 'block';
		obj_i.src = '/img/kodawari_close.gif';
	}
}

// 検索結果詳細の写真切替
function changeImage(idNo){
	var imgId = "thum" + idNo;
	if(document.all){
		document.all('photo_m').src = document.all(imgId).src;
		var imgurl = document.all(imgId).src;
		document.all('photo_m_a').href = imgurl.replace(/\.(jpg|gif)/i,"_l.$1");
	}else if(document.getElementById){
		document.getElementById('photo_m').src = document.getElementById(imgId).src;
		var imgurl = document.getElementById(imgId).src;
		document.getElementById('photo_m_a').href = imgurl.replace(/\.(jpg|gif)/i,"_l.$1");
	}
	changeImageMain();
}

// 詳細ページの写真リサイズ
// 縦画像から横画像、その逆、の入れ替えを行った際の縦横比を調整
function changeImageMain(){
	document.getElementById('photo_m').style.width = "";
	document.getElementById('photo_m').style.height = "";
	resizeImage('photo_m',400,320);
	var testW = document.getElementById('photo_m').style.width;
	var testH = document.getElementById('photo_m').style.height;
}

// 写真のリサイズ
function resizeImage(imgId,maxW,maxH){
	if(!imgId || !maxW || !maxH){ return; }
	if(document.all){
		obj = document.all(imgId);
	}else if(document.getElementById){
		obj = document.getElementById(imgId);
	}
	var imgW = obj.width;
	var imgH = obj.height;
	if(!imgW || !imgH){ return; }
	if(imgW < maxW && imgH < maxH){ return; }
	var tempW = (maxH/imgH)*imgW;
	if(tempW > maxW){
		imgH = (maxW/imgW)*imgH;
		imgW = maxW;
	}else{
		imgH = maxH;
		imgW = tempW;
	}
	obj.style.width = imgW + "px";
	obj.style.height = imgH + "px";
	positionCenter(imgId,maxW,maxH);
}


function positionCenter(imgId,maxW,maxH){
	// 画像サイズ取得
	if(document.all){
		obj = document.all(imgId);
	}else if(document.getElementById){
		obj = document.getElementById(imgId);
	}
	var imgW = obj.width;
	var imgH = obj.height;
	var positionL = (maxW - imgW) / 2;
	var positionT = (maxH - imgH) / 2;
	obj.style.marginLeft = positionL + 'px';
	obj.style.marginTop = positionT + 'px';
}


