var store = {
	//CONSTANT
	DIR_JBSTORE:"jollyboutiquestore",
	DIR_STORE:"store",
	MAP_IMAGE_01:"/common/img/store/map_01.gif",
	MAP_IMAGE_02:"/common/img/store/map_02.gif",
	MAP_IMAGE_03:"/common/img/store/map_03.gif",
	MAP_IMAGE_04:"/common/img/store/map_04.gif",
	MAP_IMAGE_05:"/common/img/store/map_05.gif",
	MAP_IMAGE_06:"/common/img/store/map_06.gif",
	MAP_IMAGE_07:"/common/img/store/map_07.gif",
	MAP_IMAGE_08:"/common/img/store/map_08.gif",
	
	//PROPERTY
	_self: null,
	maps: null,
	dir: null,
	areaNo: 0,
	
	//METHOD
	init:function()
	{
		_self = this;
		with (_self)
		{
			maps = new Array();
			maps.push(MAP_IMAGE_01);
			maps.push(MAP_IMAGE_02);
			maps.push(MAP_IMAGE_01);
			maps.push(MAP_IMAGE_03);
			maps.push(MAP_IMAGE_04);
			maps.push(MAP_IMAGE_05);
			maps.push(MAP_IMAGE_06);
			maps.push(MAP_IMAGE_07);
			maps.push(MAP_IMAGE_08);
			
			dir = getDir();
			areaNo = getAreaNo();
			
			if (dir == null) dir = DIR_JBSTORE;
			if (areaNo < 1) areaNo = 2;
			//
			changeTab(dir);
			changeMap(areaNo);
		}
		
		$("#Tab_jollyboutiquestore").click(function(){
			location.href = this.href;
			with (_self)
			{
				changeTab(DIR_JBSTORE);
			}
			window.focus();
			return false;
		});
		
		$("#Tab_store").click(function(){
			location.href = this.href;
			with (_self)
			{
				changeTab(DIR_STORE);
			}
			window.focus();
			return false;
		});
		
		$("#ClickMap area, .etc a").click(function(){
			location.href = this.href.replace("#/map/", "#/" + _self.dir + "/");
			with (_self)
			{
				areaNo = getAreaNo();
				changeMap(areaNo);
			}
			window.focus();
			return false;
		});
	},
	changeMap:function(index)
	{
		_self.areaNo = index;
		//Hide Area Block
		$("#JollyBoutiqueStore .block, #Store .block").hide();
		//Show Selected Area
		var areaIndex = 1;
		if (index > 0) areaIndex = index - 1;
		$("#JollyBoutiqueStore .block").eq(areaIndex).show();
		$("#Store .block").eq(areaIndex).show();
		//Change Map Source
		$("#JapanMap").attr("src", _self.maps[index]);
		return _self.maps[index];
	},
	changeTab:function(dir)
	{
		_self.dir = dir;
		location.href = "#/" + dir + "/" + _self.areaNo;
		
		switch (dir)
		{
			case _self.DIR_STORE:
				$("#JollyBoutiqueStore").hide();
				$("#Store").show();
				//
				$("#Tab_" + _self.DIR_STORE).addClass("current");
				$("#Tab_" + _self.DIR_JBSTORE).removeClass("current");
				break;
			default :
				$("#JollyBoutiqueStore").show();
				$("#Store").hide();
				//
				$("#Tab_" + _self.DIR_STORE).removeClass("current");
				$("#Tab_" + _self.DIR_JBSTORE).addClass("current");
				break;
		}
	},
	
	//INTERNAL METHOD
	getAreaNo:function()
	{
		var hash = _self.getHash();
		if (hash != null && hash.indexOf("/") != -1)
		{
			var dirs = new Array();
			dirs = hash.split("/");
			if (dirs.length > 2 && !isNaN(Number(dirs[2])) )
				return Number(dirs[2]);
				else return 0;
		}
		else
		{
			return 0;
		}
	},
	getDir:function()
	{
		var hash = _self.getHash();
		if (hash != null && hash.indexOf("/") != -1)
			return hash.split("/")[1];
			else return null;
	},
	getHash:function(url)
	{
		var hash = "";
		if ( (typeof url) == "string" && url.indexOf("#") != -1 )
			hash = url.replace(/.*(#.*)$/, "$1");
			else hash = location.hash;
		if (hash != "")
		{
			hash = hash.split("#")[1];
			if (hash == "") return null;
				else if (hash.indexOf("?") != -1) return hash.replace(/\?.*$/, "");
				else return hash;
		}
		else
		{
			return null;
		}
	}
}

$(document).ready(function(){
	store.init();
});

// Map Open
function popMap(url)
{
	var params = "width=850,height=920,status=yes,scrollbars=yes,menubar=yes,location=yes,toolbar=yes,resizable=yes";
	window.open(url,"mapWin", params);
}