/* ==

　初期設定

============================================================================================== */
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 = "/common/images/renew2009/sub/map/map_";

//各都道府県ページパス
var mansionPath = "http://www3.daiwahouse.co.jp/mansion/";
var bunjoPath = "http://www3.daiwahouse.co.jp/bunjo/"


/* ==

　処理

============================================================================================== */
$(function(){

	//マップ遷移時に別地域の画像が表示される現象に対応
	//if($(".section > .sub").attr("id") == "mapAll"){
	//	$(".section > .sub > .map ul.btn").children("li").each(function(i){
	//		$(this).find("a").bind("click", function(){
	//			var thisArea = area[i];
	//			$(".section > .sub").attr("id", area[i]);
	//			mapImgChg(thisArea);			
	//		});
	//	});
	//}else{
//		mapImgChg("all")
	//	areaAll();
	//}

	//地図・都道府県ボタン画像プリロード
	var preloadImgs = [];
	var mapImgs = preloadImgs;
	for(var i=0; i<area.length; i++){
		mapImgs[i] = new Image();
		mapImgs[i].src = "/common/images/renew2009/sub/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 = "/common/images/renew2009/sub/map/btn_pref" + area[thisArea]["code"][j] + ".gif";
		}
		
	}
	//「全国を表示」ボタン
	mapImgs["btnAll"] = new Image();
	mapImgs["btnAll"].src = "/common/images/renew2009/sub/map/btn_all.gif";
	
});


function mapImgChg(thisArea){

	//地図画像
	var mapImg = "<img src=\"" + mapImgPath + thisArea + ".gif\" alt=\"\" width=\"200\" height=\"135\">";
	$(".section > .sub > .map > p.img").html(mapImg);

	//ボタン
	if(thisArea == "all"){

		$(".section > .sub").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>";
		}
		$(".section > .sub > .map > ul.btn").html(btnArea);
		
		//「全国を表示」削除
		$(".section > .sub > .map > p.btn_areaAll").remove();

		$(".section > .sub > .map > ul.btn").children("li").each(function(i){
			$(this).find("a").bind("click", function(){

				var thisArea = area[i];
				$(".section > .sub").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] + "\">";

			if($("body").attr("id") == "mansion"){
//				if(thisArea == "chubu2"){
//					btnPref += "<a href=\"" + mansionPath + "chubu/" + area[thisArea]["code"][j] + ".html\" tite=\"" + area[thisArea]["txt"][j] + "\">";
//				}else{
//					btnPref += "<a href=\"" + mansionPath + thisArea + "/" + area[thisArea]["code"][j] + ".html\" tite=\"" + area[thisArea]["txt"][j] + "\">";
//				}
				btnPref += "<a href=\"http://www3.daiwahouse.co.jp/mansion/search.html?ads_ken=" + area[thisArea]["code"][j] + "&mode=000100&disp=1\" tite=\"" + area[thisArea]["txt"][j] + "\">";
			}else if($("body").attr("id") == "bunjo"){
//				if(thisArea == "chubu2"){
//					btnPref += "<a href=\"" + bunjoPath + "chubu/" + area[thisArea]["code"][j] + ".html\" tite=\"" + area[thisArea]["txt"][j] + "\">";
//				}else{
//					btnPref += "<a href=\"" + bunjoPath + thisArea + "/" + area[thisArea]["code"][j] + ".html\" tite=\"" + area[thisArea]["txt"][j] + "\">";
//				}
				btnPref += "<a href=\"http://www3.daiwahouse.co.jp/bunjo/search.html?ads_ken=" + area[thisArea]["code"][j] + "&mode=001000&disp=1\" tite=\"" + area[thisArea]["txt"][j] + "\">";
			}
			btnPref += "<span>" + area[thisArea]["txt"][j] + "</span>";
			btnPref += "</a></li>";
			
		}
		$(".section > .sub > .map > ul.btn").html(btnPref);
		areaAll();
		
	}
}

function areaAll(){ //「全国を表示」表示

	if($(".section > .sub > .map > p.btn_areaAll")){ $(".section > .sub > .map > p.btn_areaAll").remove(); }

	$(".section > .sub > .map").append("<p class=\"btn_areaAll\"><a href=\"javascript:void(0);\" title=\"全国を表示\">全国を表示</a></p>");
	$(".section > .sub > .map > p.btn_areaAll").find("a").bind("click", function(){
		mapImgChg("all");
	});

}
