var b_id = {}; // 配列を初期化
var wd;

$(function(){


	//$('#kouho_box').hide();
	/*$('#search-box input:text.free').focus(function(){
			//$('#kouho_box').show();
			$(this).after( kouho_wd() );
			$('p.fwd_k_wd').click(function(){
				var dt = $('#search-box input:text.free').val();
				$('#search-box input:text.free').val( dt +" "+ $(this).text());
			});
			$('#reset_box img').click(function(){
				$('#search-box input:text.free').val( "" );
			});
	}).blur(function(){ setTimeout( function(){ $("#kouho_box").remove(); $("#reset_box").remove(); }, 200); });*/

	

	$('#search-box input:checkbox').click(function(){
		if(this.checked){
			$(this).parent().addClass('checked');
		}else{
			$(this).parent().removeClass('checked');
		}
	});

	$('#search-box input:radio').click(function(){
		$('#search-box input:radio').parent().removeClass('checked');
		$(this).parent().addClass('checked');

	});

	$('#c_all').click(function(){
		if(this.checked){
			$('input.eki').attr('checked','checked');
		}else{
			$('input.eki').removeAttr('checked');
		}
	});


	$('#b_all').click(function(){
		if(this.checked){
			$('input.inq').attr('checked','checked');
		}else{
			$('input.inq').removeAttr('checked');
		}
	});

	

	$("#search_more").click(function(){
		if ($(this).is(".search_show")){
			$(this).removeClass("search_show");
			$(this).addClass("search_hide");
			$(this).text("詳細な条件を閉じる");
			$("#setubi_box").show();
		}else{
			$(this).removeClass("search_hide");
			$(this).addClass("search_show");
			$(this).text("もっと詳細な条件を設定する");
			$("#setubi_box").hide();
		}
	});

	//メインビジュアルバナー
	$("#main-img-menu img").mouseover(function(){
		b_id = $(this).attr("id").split("btn");
		i = parseInt(b_id[1]);
		var Height = nowHeihgt - imgHeight * (i-1);
		$("#img_box").animate({
		    top: '+='+Height+'px'
		}, "slow");
		nowHeihgt = imgHeight * (i-1);
	});

});


function kouho_wd(){
	wd = '<div id="kouho_box">';
	wd += '<p>候補ワード<span>(クリックできます。)</span></p>';
	wd += '<p class="fwd_k_wd">江坂</p>';
	wd += '<p class="fwd_k_wd">分譲</p>';
	wd += '<p class="fwd_k_wd">新築</p>';
	wd += '<p class="fwd_k_wd">駐車場</p>';
	wd += '<p class="fwd_k_wd">ペット</p>';
	wd += '<p class="fwd_k_wd">緑地公園</p>';
	wd += '</div>';
	wd += '<div id="reset_box">';
	wd += '<img src="../common/img/2011/s_reset.jpg" alt="×" />';
	wd += '</div>';
	return wd;
}
function kouho_sel(){
	alert($(this).text());
	$('#search-box input:text.free').val($(this).text());
}

function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}


$(document).ready(function(){  
	$("#setubi_box").hide();
});



//*************************************************
//**** 検索条件取得 *******************************
//*************************************************
function search_add(){

	var url_condision = "";

	//フリーワード
	if($("input.free").val().length > 0){
		var str = utf.URLencode($("input.free").val());
		url_condision += "/fg:";
		url_condision += $("input.fg:checked").val();
		url_condision += "/fr:";
		if(navigator.userAgent.indexOf("Safari") != -1){ // 文字列に「Safari」が含まれている場合
			url_condision += str;
		}else{
			url_condision += $("input.free").val();
		}
	}

	//駅
	if($("input.eki:checked").length > 0){
		url_condision += "/eki:";
		$("input.eki:checked").each(function () {
			url_condision += $(this).val() +"-";
		});
	}

	//市
	if($("input.city:checked").length > 0){
		url_condision += "/city:";
		$("input.city:checked").each(function () {
			url_condision += $(this).val() +"-";
		});
	}

	//人気条件
	if($("input.popular:checked").length > 0){
		url_condision += "/popular:";
		$("input.popular:checked").each(function () {
			url_condision += $(this).val() +"-";
		});
	}

	//間取
	if($("input.madori:checked").length > 0){
		url_condision += "/madori:";
		$("input.madori:checked").each(function () {
			url_condision += $(this).val() +"-";
		});
	}

	//設備
	if($("input.setubi:checked").length > 0){
		url_condision += "/setubi:";
		$("input.setubi:checked").each(function () {
			url_condision += $(this).val() +"-";
		});
	}

	//下限賃料
	if($("select.tinryo_s option:selected").val()){
		url_condision += "/tinryo_s:";
		url_condision += $("select.tinryo_s option:selected").val();
	}

	//上限賃料
	if($("select.tinryo_e option:selected").val()){
		url_condision += "/tinryo_e:";
		url_condision += $("select.tinryo_e option:selected").val();
	}

	//上限初期費用
	if($("select.start_e option:selected").val()){
		url_condision += "/start_e:";
		url_condision += $("select.start_e option:selected").val();
	}

	//下限初期費用
	if($("select.start_s option:selected").val()){
		url_condision += "/start_s:";
		url_condision += $("select.start_s option:selected").val();
	}

	//築年月
	if($("select.tikunengetu option:selected").val()){
		url_condision += "/tikunengetu:";
		url_condision += $("select.tikunengetu option:selected").val();
	}

	//下限面積
	if($("select.menseki_s option:selected").val()){
		url_condision += "/menseki_s:";
		url_condision += $("select.menseki_s option:selected").val();
	}

	//上限面積
	if($("select.menseki_e option:selected").val()){
		url_condision += "/menseki_e:";
		url_condision += $("select.menseki_e option:selected").val();
	}

	//徒歩
	if($("select.toho option:selected").val()){
		url_condision += "/toho:";
		url_condision += $("select.toho option:selected").val();
	}

	//空室確認日
	if($("select.empty option:selected").val()){
		url_condision += "/em:";
		url_condision += $("select.empty option:selected").val();
	}

	//空室状況
	if($("input.empty:checked").length > 0){
		url_condision += "/jk:";
		$("input.empty:checked").each(function () {
			url_condision += $(this).val();
		});
	}

	//管理費
	if($("input.kanrihi:checked").length > 0){
		url_condision += "/kanrihi:";
		$("input.kanrihi:checked").each(function () {
			url_condision += $(this).val();
		});
	}

	//駅全部
	if($("input#c_all:checked").length > 0){
		url_condision += "/c_all:";
		$("input.#c_all:checked").each(function () {
			url_condision += $(this).val();
		});
	}


	return url_condision;

}

function searchPage(){

	document.location = "http://www.apanavi.jp/search/search.php#"+search_add();
	
}


function searchPage2(){
	$("#fm").attr('action', '../search/search.php#'+search_add());
	document.frmMain.submit()
}




