/* ==

　初期設定

============================================================================================== */
var area = Array("hokkaido", "tohoku", "kanto", "chubu2", "chubu", "kinki", "chugoku", "shikoku", "kyushu");
area["txt"] = Array("北海道エリア", "東北エリア", "関東エリア", "北陸・信越エリア", "中部エリア", "近畿エリア", "中国エリア", "四国エリア", "九州エリア");

area["hokkaido"] = [];
area["hokkaido"]["code"] = Array("1");
area["hokkaido"]["txt"] = Array("北海道");

area["tohoku"] = [];
area["tohoku"]["code"] = Array("2", "3", "4", "5", "6", "7");
area["tohoku"]["txt"] = Array("青森", "岩手", "宮城", "秋田", "山形", "福島");

area["kanto"] = [];
area["kanto"]["code"] = Array("8", "9", "10", "11", "12", "13", "14", "19");
area["kanto"]["txt"] = Array("茨城", "栃木", "群馬", "埼玉", "千葉", "東京", "神奈川", "山梨");

area["chubu2"] = [];
area["chubu2"]["code"] = Array("15", "16", "17", "18", "20");
area["chubu2"]["txt"] = Array("新潟", "富山", "石川", "福井", "長野");

area["chubu"] = [];
area["chubu"]["code"] = Array("21", "22", "23", "24");
area["chubu"]["txt"] = Array("岐阜", "静岡", "愛知", "三重");

area["kinki"] = [];
area["kinki"]["code"] = Array("25", "26", "27", "28", "29", "30");
area["kinki"]["txt"] = Array("滋賀", "京都", "大阪", "兵庫", "奈良", "和歌山");

area["chugoku"] = [];
area["chugoku"]["code"] = Array("31", "32", "33", "34", "35");
area["chugoku"]["txt"] = Array("鳥取", "島根", "岡山", "広島", "山口");

area["shikoku"] = [];
area["shikoku"]["code"] = Array("36", "37", "38", "39");
area["shikoku"]["txt"] = Array("徳島", "香川", "愛媛", "高知");

area["kyushu"] = [];
area["kyushu"]["code"] = Array("40", "41", "42", "43", "44", "45", "46", "47");
area["kyushu"]["txt"] = Array("福岡", "佐賀", "長崎", "熊本", "大分", "宮崎", "鹿児島", "沖縄");


//地図画像のパス
var mapImgPath = "top/images/map/map_";

//各都道府県ページパス
var kyotenPath = "/kyoten/";


/* ==

　処理

============================================================================================== */
$(function(){

	//地図・都道府県ボタン画像プリロード
	var preloadImgs = [];
	var mapImgs = preloadImgs;
	for(var i=0; i<area.length; i++){
		mapImgs[i] = new Image();
		mapImgs[i].src = "top/images/map/map_" + area[i] + ".gif";
		
		//都道府県ボタン
		var preloadBtns = [];
		var prefBtns = preloadBtns;
		var thisArea = area[i];
		for(var j=0; j<area[thisArea]["code"].length; j++){
			prefBtns[j] = new Image();
			prefBtns[j].src = "top/images/map/btn_pref" + area[thisArea]["code"][j] + ".gif";
		}
		
	}
	//「全国を表示」ボタン
	mapImgs["btnAll"] = new Image();
	mapImgs["btnAll"].src = "top/images/map/btn_all.gif";

});


function mapImgChg(thisArea){
	
	//地図画像
	var mapImg = "<img src=\"" + mapImgPath + thisArea + ".gif\" alt=\"\" width=\"330\" height=\"220\" />";
	$("#kyoten div.map > p.img").html(mapImg);

	//ボタン
	if(thisArea == "all"){

		$(".container").attr("id", "mapAll");
		
		var btnArea = "";
		for(var j=0; j<area.length; j++){
			btnArea += "<li class=\"area_" + area[j] + "\">";
			btnArea += "<a href=\"javascript:void(0);\" title=\"" + area["txt"][j] + "\"><span>" + area["txt"][j] + "</span></a>";
			btnArea += "</li>";
		}
		$("#kyoten div.map > ul.btn").html(btnArea);
		
		//「全国を表示」削除
		$("#kyoten p.btn_areaAll").remove();

		$("#kyoten div.map ul.btn").children("li").each(function(i){
			$(this).find("a").bind("click", function(){

				var thisArea = area[i];
				$(".container").attr("id", area[i]);
				mapImgChg(thisArea);			

			});
		});

	}else{
	
		var btnPref = "";
		for(var j=0; j<area[thisArea]["code"].length; j++){

				btnPref += "<li class=\"pref" + area[thisArea]["code"][j] + "\">";
				btnPref += "<a href=\"" + kyotenPath + "search.html?ads_ken=" + area[thisArea]["code"][j] + "&mode=1111111\" title=\"" + area[thisArea]["txt"][j] + "\">";
				btnPref += "<span>" + area[thisArea]["txt"][j] + "</span>";
				btnPref += "</a></li>";
			
		}
		$("#kyoten div.kyoten > .map > ul.btn").html(btnPref);
		areaAll();
		
	}
}

function areaAll(){ //「全国を表示」表示

	if($("#kyoten div.map p.btn_areaAll")){ $("#kyoten div.map p.btn_areaAll").remove(); }

	$("#kyoten div.map").prepend("<p class=\"btn_areaAll\"><a href=\"javascript:void(0);\" title=\"全国を表示\">全国を表示</a></p>");
	$("#kyoten div.map p.btn_areaAll").find("a").bind("click", function(){
		mapImgChg("all");
	});

}

//検索ボタン押下処理
function docheck() { 
	var mode='0';
	var mode1='0';
	var mode2='0';
	var mode3='0';
	var mode4='0';
	var mode5='0';
	var mode6='0';
    if(document.chk_form.shiten.checked){ 
		mode1 = '1';
	}
    if(document.chk_form.tenjijo.checked){ 
		mode2 = '1';
	}
    if(document.chk_form.bunjo.checked){ 
		mode3 = '1';
	}
    if(document.chk_form.mansion.checked){ 
		mode4 = '1';
	}
	if(document.chk_form.event.checked){ 
		mode6 = '1';
	}
	if(document.chk_form.etc.checked){ 
		mode5 = '1';
	}
	mode = mode1 + mode2 + mode3 + mode4 + mode6 + mode5;
	document.location = disp_kyoten_url+"?ads_ken="+document.chk_form.ads_ken.value+"&mode="+mode;

}

//検索ボタン押下処理（条件から探す画面）
function docheck() { 
	var mode='0';
	var mode1='0';
	var mode2='0';
	var mode3='0';
	var mode4='0';
	var mode5='0';
	var mode6='0';
    if(document.chk_form.shiten.checked){ 
		mode1 = '1';
	}
    if(document.chk_form.tenjijo.checked){ 
		mode2 = '1';
	}
    if(document.chk_form.bunjo.checked){ 
		mode3 = '1';
	}
    if(document.chk_form.mansion.checked){ 
		mode4 = '1';
	}
	if(document.chk_form.event.checked){ 
		mode6 = '1';
	}
	if(document.chk_form.etc.checked){ 
		mode5 = '1';
	}
	mode = mode1 + mode2 + mode3 + mode4 + mode6 + mode5;
	document.location = disp_kyoten_url+"?ads_ken="+document.chk_form.ads_ken.value+"&mode="+mode;

}

//施設ボタン押下処理（施設イベントを探す画面）
function docheckShisetsu(mode) { 
	document.location = disp_kyoten_url+"?ads_ken="+document.chk_form2.ads_ken2.value+"&mode="+mode;
}

//賃貸住宅(D-Room)ボタン押下処理
function docheckChintai() { 

	var intArea = document.chk_form2.ads_ken2.value;
	
	if (intArea == '1001') {
		document.location = "/chintai/hokkaido/index.html";
	} else if (intArea == '1002') {
		document.location = "/chintai/tohoku/index.html";
	} else if (intArea == '1003') {
		document.location = "/chintai/kanto/index.html";
	} else if (intArea == '1004') {
		document.location = "/chintai/chubu1/index.html";
	} else if (intArea == '1005') {
		document.location = "/chintai/chubu2/index.html";
	} else if (intArea == '1006') {
		document.location = "/chintai/kinki/index.html";
	} else if (intArea == '1007') {
		document.location = "/chintai/chugoku/index.html";
	} else if (intArea == '1008') {
		document.location = "/chintai/shikoku/index.html";
	} else if (intArea == '1009') {
		document.location = "/chintai/kyushu/index.html";
	} else {
		document.location = "/chintai/index.html";
	}
}


