
var imgPrefix = "/images/img2/map/";

var maps_name = [
"map_hawaii",
"map_hawaiiland",
"map_kauai",
"map_maui",
"map_morokai",
"map_oahu",
"map_ranai"
];

var maps_length = [ 7, 21, 15, 20, 8, 21, 2 ];

var map_hawaiiland_childs = {
	"000201":"map_hawaiiland_21",
	"000202":"map_hawaiiland_04",
	"000203":"map_hawaiiland_05",
	"000204":"map_hawaiiland_09",
	"000205":"map_hawaiiland_11",
	"000206":"map_hawaiiland_17",
	"000207":"map_hawaiiland_18",
	"000208":"map_hawaiiland_19",
	"000209":"map_hawaiiland_02",
	"000210":"map_hawaiiland_16",
	"000211":"map_hawaiiland_14",
	"000212":"map_hawaiiland_12",
	"000213":"map_hawaiiland_20",
	"000214":"map_hawaiiland_15",
	"000215":"map_hawaiiland_03",
	"000216":"map_hawaiiland_06",
	"000217":"map_hawaiiland_08",
	"000218":"map_hawaiiland_07",
	"000219":"map_hawaiiland_10",
	"000220":"map_hawaiiland_13",
	"000221":"map_hawaiiland_01"
}

var map_kauai_childs = {
	"000401":"map_kauai_09",
	"000402":"map_kauai_07",
	"000403":"map_kauai_08",
	"000404":"map_kauai_06",
	"000405":"map_kauai_02",
	"000406":"map_kauai_03",
	"000407":"map_kauai_04",
	"000408":"map_kauai_14",
	"000409":"map_kauai_15",
	"000410":"map_kauai_13",
	"000411":"map_kauai_10",
	"000412":"map_kauai_12",
	"000413":"map_kauai_11",
	"000414":"map_kauai_05",
	"000415":"map_kauai_01"
}

var map_maui_childs = {
	"000301":"map_maui_09",
	"000302":"map_maui_15",
	"000303":"map_maui_07",
	"000304":"map_maui_11",
	"000305":"map_maui_12",
	"000306":"map_maui_17",
	"000307":"map_maui_05",
	"000308":"map_maui_19",
	"000309":"map_maui_14",
	"000310":"map_maui_16",
	"000311":"map_maui_06",
	"000312":"map_maui_08",
	"000313":"map_maui_20",
	"000314":"map_maui_03",
	"000315":"map_maui_02",
	"000316":"map_maui_04",
	"000317":"map_maui_13",
	"000318":"map_maui_10",
	"000319":"map_maui_18",
	"000320":"map_maui_01"
}

var map_morokai_childs = {
	"000501":"map_morokai_07",
	"000502":"map_morokai_05",
	"000503":"map_morokai_04",
	"000504":"map_morokai_03",
	"000505":"map_morokai_02",
	"000506":"map_morokai_08",
	"000507":"map_morokai_06",
	"000508":"map_morokai_01"
}

var map_oahu_childs = {
	"000101":"map_oahu_11",
	"000102":"map_oahu_14",
	"000103":"map_oahu_15",
	"000104":"map_oahu_02",
	"000105":"map_oahu_07",
	"000106":"map_oahu_05",
	"000107":"map_oahu_19",
	"000108":"map_oahu_13",
	"000109":"map_oahu_06",
	"000110":"map_oahu_10",
	"000111":"map_oahu_04",
	"000112":"map_oahu_03",
	"000113":"map_oahu_21",
	"000114":"map_oahu_17",
	"000115":"map_oahu_18",
	"000116":"map_oahu_20",
	"000117":"map_oahu_08",
	"000118":"map_oahu_16",
	"000119":"map_oahu_09",
	"000120":"map_oahu_01"
}

var map_ranai_childs = {
	"000601":"map_ranai_02",
	"000602":"map_ranai_01"
}

var def_childs = {
	"000001":"map_oahu_01",
	"000002":"map_hawaiiland_01",
	"000003":"map_maui_01",
	"000004":"map_kauai_01",
	"000005":"map_morokai_01",
	"000006":"map_ranai_01"
}

var maps_ids = {

	"000002":["map_hawaiiland",map_hawaiiland_childs],
	"000004":["map_kauai", map_kauai_childs],
	"000003":["map_maui",map_maui_childs],
	"000005":["map_morokai",map_morokai_childs],
	"000001":["map_oahu", map_oahu_childs],
	"000006":["map_ranai", map_ranai_childs]
};

var default_area1Id = null;
var default_area2Id = null;
var default_open_map = "map_hawaii_01";

var lockImgMap = false;

var IS_IE = window.navigator.userAgent.toLowerCase().indexOf("msie") > 0 ? true : false;
var iframe2 = null;
//-------------------------------------------------------------------------------//

var ImageContainer = {
	container:{},
	get:function(key){
		return this.container[key];
	},
	put:function(key, value){
		this.container[key] = value;
	},
	getLength:function(){
		var len = 0;
		for( var key in this.container ){
			len++;
		}
		return len;
	}
}

//-------------------------------------------------------------------------------//

function getDefaultMap(){
	if( default_area1Id == null || default_area1Id == "" ){
		return default_open_map;
	}
	if( default_area2Id == null || default_area2Id == "" ){
		for(var k1 in def_childs){
			if( k1 == default_area1Id) return def_childs[k1];
		}
	}
	
	var obj = maps_ids[default_area1Id][1];
	
	for( var k2 in obj ){
		if( k2 == default_area2Id ) return obj[k2];
	}
	
}

function preLoad(){
	
	for( var i =1; i <= maps_name.length; i++ ){
		prefetchingImg( maps_name[i-1], maps_length[i-1] );
	}
	
}

function prefetchingImg(strName, len){
	var mn = strName.split("_")[1];
	var strPath = imgPrefix + strName + "/";
	var _0 = "_0"
	var _Str = "_";
	for( var j=1; j<=len; j++){
		var imgArea = new Image();
		imgArea.useMap = "#" + strName;
		if(j < 10 ){
			imgArea.src = strPath + mn +  _0 + j + ".gif";
			ImageContainer.put( strName + _0 + j, imgArea);
		}else{
			imgArea.src = strPath + mn +  _Str + j + ".gif";
			ImageContainer.put(strName + _Str + j, imgArea);
		}

	}
}

function showMapImg(){
	if( ImageContainer.getLength() == 0 ){
		preLoad();
	}
	$("#subSearchDivMap").html("<div></div>");
	var tab02on = document.getElementById('header-search-tab02on');
	var tab02off = document.getElementById('header-search-tab02off');
	tab02on.style.display = "";
	tab02off.style.display = "none";
	var pos = Position.cumulativeOffset(tab02on);
	var box15 = document.getElementById('aj-box15');
	box15.style.display = "";
	box15.style.position = "absolute";
	box15.style.zIndex = 1;
	box15.style.left = pos.x + "px";
	box15.style.top = (pos.y + 20) + "px";
	
	if( IS_IE ){
		if( iframe2 == null ){
			iframe2 = document.createElement('iframe');
		}
		iframe2.style.position = "absolute";
		iframe2.style.width = box15.offsetWidth;
		iframe2.style.height = box15.offsetHeight;
		iframe2.style.left = pos.x + "px";
		iframe2.style.top = (pos.y + 20) + "px";
		document.body.appendChild(iframe2);
	}
	
	var opened_map = getDefaultMap();
	showMapArea(opened_map);
	
	resetGoogleMap_Search();
}

function unlockImgMap(){
	lockImgMap = false;
}

function showMapArea(strnm) {
	if( lockImgMap ) return;
	lockImgMap = true;
	var subSearchDiv = document.getElementById("subSearchDivMap");
	closeMapImg(subSearchDiv);
	subSearchDiv.appendChild(ImageContainer.get(strnm));
	window.setTimeout("unlockImgMap()", 100);
}

function closeMapImg(subSearchDiv){	
	if( subSearchDiv == "empty" ){
		$("#subSearchDivMap").html("<div></div>");
		if( IS_IE ){
			if(iframe2 != null){
				document.body.removeChild(iframe2);
				iframe2 = null;
			}
		}
		var tab02on = document.getElementById('header-search-tab02on');
		var tab02off = document.getElementById('header-search-tab02off');
		tab02on.style.display = "none";
		tab02off.style.display = "";
		var box15 = document.getElementById('aj-box15');
		box15.style.display = "none";
				
		resetGoogleMap_Search();	
		return;
	}
	if( subSearchDiv != null && subSearchDiv.hasChildNodes() ){
		for( var k=0; k<subSearchDiv.childNodes.length; k++ ){
			subSearchDiv.removeChild(subSearchDiv.firstChild);
		}
	}
}

function resetGoogleMap_Search() {
		var mapgoogleall = document.getElementById("map-google-all");
		var head = document.getElementById("headmap");
		var foot = document.getElementById("footmap");
		if(mapgoogleall != null && head != null && foot != null){
			resetGoogleMapPos();
		}
}
