hs.align="center";
hs.onKeyDown = function (sender, e) {
	if([33,34,37,38,39,40].indexOf(e.keyCode)!=-1)	return false;
}
var shopMap=Class.create();
shopMap.prototype={
	initialize:function(){
		this.URL_GMAPLOADER="../common/gmap_loader.php";
		this.ID_IMGWRAP="shoplist";
		this.FILENAME_BUTTON="btn_map.jpg";
		this.ID_HSLINK="hs_link";
		this.ID_HSWRAPPER="hs_wrapper";
		//this.CLASS_GMAPWRAPPER="gmapwrapper";
		this.GMAP_WIDTH=500;
		this.GMAP_HEIGHT=500;
		this.GMAP_ZOOM=15;
		
		this.imgs=[];
		this.loadedMaplist=[];
		
		try{
			new Ajax.Request(this.URL_GMAPLOADER,{
				onComplete:this.setDatas.bind(this)
			});
		}catch(e){
			alert(e);
			return false;
		}
		
		Event.observe(window,"load",this.load.bind(this),false);
	},
	setDatas:function(obj){
		var _shops=eval("("+obj.responseText+")");
		this.shops=_shops["shops"];
		this.fire();
	},
	load:function(){
		try{
			if(!$(this.ID_IMGWRAP)) return false;
			$A($(this.ID_IMGWRAP).getElementsByTagName("img")).each(function(imgElem){
				if(imgElem.getAttribute("src").indexOf(this.FILENAME_BUTTON)==-1) return false;
				this.imgs.push(imgElem)
				
			}.bind(this));
			
			/*var wraps=$A(document.getElementsByClassName(this.CLASS_IMGWRAP));
			wraps.each((function(wrap){
				var tables=$A(wrap.getElementsByTagName("table"));
				tables.each((function(table){
					var _imgs=$A(table.getElementsByTagName("img"));
					if(_imgs.length>0) this.imgs.push(_imgs[0]);
				}).bind(this));
			}).bind(this));*/
			this.insertHSwrapper();
			
			this.fire();
		} catch(e){
			alert(e);
			return null;
		}		
	},
	fire:function(){
		if(!((typeof this.shops=="object") && (this.imgs.length>0))) return false;
		
		/* Mapボタンの準備 */
		this.imgs.each((function(im){
			if(!this.shops[im.alt]) return false;
			Event.observe(im,"click",this.click.bind(this),false);
			im.style.display="inline";
			im.style.cursor="pointer";
		}).bind(this));
		
		/* クリック後、HSポップの次に行う処理 */
		hs.Expander.prototype.onAfterExpand=(function(sender){
			var tempdata=this.temp_shop_data;
			var shopname= tempdata["name"];
			var lat = Number(tempdata["lat"]);
			var lng = Number(tempdata["lng"]);
			var desc =tempdata["desc"];
			var zoom=this.GMAP_ZOOM;
			
			if(!this.loadedMaplist[shopname]){
			
				/* GMAP基本地図生成 */
				
				var gmapwrappers = sender.content.getElementsByTagName("span");
				
				this.map = new GMap2(gmapwrappers[0]);
				this.map.setCenter(new GLatLng(lng,lat),zoom);
				this.map.addControl(new GLargeMapControl());
				this.map.addControl(new GMapTypeControl());
				this.map.setMapType(G_NORMAL_MAP);
				
				var marker = new GMarker(new GPoint(lat,lng), { title:shopname});
				this.map.addOverlay(marker);
				this.loadedMaplist[shopname]=marker;
				
				marker.openInfoWindowHtml(desc);
			} else {
				this.map.setCenter(new GLatLng(lng,lat),zoom);
				var marker=this.loadedMaplist[shopname];
				marker.openInfoWindowHtml(desc);
			}

		}).bind(this)
	},
	click:function(e){
		/* Mapボタンのaltから店舗データのセット */
		var altst=Event.element(e).alt;
		if(!altst) return false;
		if(!this.shops[altst]) return false;
		this.temp_shop_data=this.shops[altst];
		this.temp_shop_data["name"]=altst;
		
		hs.htmlExpand(Event.element(e),{
				contentId:this.ID_HSWRAPPER,
				transitions : [],
				fadeInOut : false,
				width:this.GMAP_WIDTH
			} 
		);

	},
	insertHSwrapper:function(){
		// GMAP用
		var ar=[],c=0;
		ar[c++]='<div class="highslide-html-content" id="'
		ar[c++]=this.ID_HSWRAPPER;
		ar[c++]='"><div class="highslide-header"><ul><li class="highslide-close"><a href="#" onclick="return hs.close(this)">Close</a></li></ul></div>';
		ar[c++]='<div class="highslide-body">';
		ar[c++]='	<span style="display:block;width:';
		ar[c++]=this.GMAP_WIDTH;
		ar[c++]='px; height:';
		ar[c++]=this.GMAP_HEIGHT;
		ar[c++]='px; margin:0px; padding:0px;"></span><div id="closebutton" class="highslide-overlay closebutton" onclick="return hs.close(this)" title="Close"></div>  </div>';
		ar[c++]='</div>';
		new Insertion.Bottom(document.body, ar.join(""));
	}
}
var shopmap=new shopMap();