(function(){

	var _MacMap = {
		_apiModuleCommonName : "http://"+window.location.host+"/api/v20/mcd/shopSearch?charset=UTF-8&format=json&soon=30&limit=1000",
		_mapInstance : null,
		_layerInstance : null,
		_routeStart : null,
		_startCenterPoint:null,
		_startScale:null,
		_mapMoveFirst : true,
		_firstSearch : true,
		_searchBasePoint : null,
		_shopList : null,
		_isPageDetail : false,
		searchMode : 0,//public.
		CONDITION_PK : 1,//car parking.
		CONDITION_DT : 2,//drive through.
		CONDITION_DS : 4,//abairable ds.
		CONDITION_BP : 8,//birthday party.
		CONDITION_PL : 16,//play land.
		CONDITION_AD : 32,//mc adventure.
		CONDITION_LS : 64,//100 over.
		CONDITION_BF : 128,//breakfast.
		CONDITION_24 : 256,//24h shop.
		reset : function() {
			_MacMap._mapInstance = null;
			_MacMap._layerInstance = null;
			_MacMap._startCenterPoint = null;
			_MacMap._firstSearch = true;
			_MacMap._shopList = null;
			_MacMap._searchBasePoint = null;
			_MacMap._mapMoveFirst = true;
		},
		search : function(target, callback) {
			var module = _MacMap._apiModuleCommonName;

			//地図ページか、店舗詳細ページか。
			var pathname = window.location.pathname;
			
			//TODO:route表示の調整。
			var params;
            
			var mapObj, box;
			if(_MacMap._firstSearch) {
				mapObj = _MacMap.createInstance();
                if(_MacMap._isPageDetail) {
				    box = mapObj["map"].getMapBoundBox(target, 15);
                } else {
				    box = mapObj["map"].getMapBoundBox(target, 13);
                }
				_MacMap._mapInstance = mapObj["map"];
				_MacMap._layerInstance = mapObj["layer"];
				module += "&area="+(box.maxlat + 0.025)+","+(box.maxlon + 0.025)+"-"+(box.minlat - 0.025)+","+(box.minlon - 0.025);
				params = null;
            }else {
			    var selfMap = _MacMap._mapInstance;
		        if( selfMap.getMapScale() > 9){
					box = _MacMap._mapInstance.getMapBoundBox(target, _MacMap._mapInstance.getMapScale());
				    module += "&area="+(box.maxlat + 0.025)+","+(box.maxlon + 0.025)+"-"+(box.minlat - 0.025)+","+(box.minlon - 0.025);
				    params = null;
                } else {
				    params = {
					    point:target.lat+","+target.lon,
					    radius:5000
				    };
                }
            }
			_MacMap._searchBasePoint = target;
			
			var ajaxObj = {
				type : "GET",
				url : module,
				data : params,
				success : function(result){
					if(window.location.pathname.indexOf("search_top2") >= 0) {
						$("#map").css({display:"block"});
						$("#searchmap").css({display:"none"});
					}
					var obj = eval("("+result+")");
					_MacMap._shopList = obj.record
					callback();
				}
			};
			
			$.ajax(ajaxObj);
		},
		createInstance : function() {
			var selfMap = _MacMap._mapInstance;
			var selfLayer = _MacMap._layerInstance;
			if(!selfMap && !selfLayer) {
				selfMap = new ZdcMap($("#"+_MacSMap.htmlMapId).get(0));
				selfMap.setMapType('6');
				selfMap.reflashMap();
				selfLayer = new ZdcUserLayer();
				selfMap.addUserLayer(selfLayer);
				_MacMap._mapInstance = selfMap;
				_MacMap._layerInstance = selfLayer;
			}
			
			return {"map":selfMap,"layer":selfLayer};
		},
		display : function(point) {
			if(_MacMap._shopList == null) {
				return;
			}
			var self = _MacMap;
			var selfMap = self._mapInstance;
			var selfLayer = self._layerInstance;
			
			if(point) {
				self._startCenterPoint = point;
			}
			else {
				self._startCenterPoint = self._searchBasePoint;
			}
			self._startScale = selfMap.getMapScale();
			_routeStart = point;
			$("#"+_MacSMap.htmlAreaId).css({display:"none"});
			$("#"+_MacSMap.htmlRailId).css({display:"none"});
			$("#"+_MacSMap.htmlSubRailId).css({display:"none"});
			var userlay, map;
			//マップ表示、既にインスタンスを生成している場合は使い回し。
			if(!_MacMap._firstSearch) {
				$("#Map").css({display:"block"});
				selfLayer.clearMarker(false);
			}
			else{
				var mapObj = _MacMap.createInstance();
				$("#"+_MacSMap.htmlMapId).css({display:"block"});
				selfMap = mapObj["map"];
				selfLayer = mapObj["layer"];
				if(_MacMap._isPageDetail) {
				    selfMap.setMapLocation(self._startCenterPoint, 15);  // 1/5000
				    self._startScale = 15;
                } else {
				    selfMap.setMapLocation(self._startCenterPoint, 13);  // 1/10000
				    self._startScale = 13;
                }
				selfMap.addMapCenter(new ZdcMapCenter());
				selfMap.setWheelType(2);
				selfMap.addMapCenter(new ZdcMapCenter('3'));
                // ズームコントローラー
	            var zomctl = new ZdcUserZoomControl();
	            zomctl.setImage('/shop/map/shared/graphic/navi_slidebar.png',    // ズームコントロール画像URI
					            new ZdcSize(26, 175),              // ズームコントロールサイズ
					            '/shop/map/shared/graphic/navi_arrow.png', // グリッド部画像URI
					            new ZdcSize(26, 22),               // グリッド部サイズ
					            null,                              // ズームコントロール影画像URI
					            null                               // ズームコントロール影サイズ
				);

	            // アクションボタンを生成する
	            zomctl.setAction('zoomOut', 4, 4  , 22, 22);            // (action id,pixel area)
	            zomctl.setAction('zoomIn' , 4, 153, 22, 171);
	            //zomctl.setAction('slither', 5, 10 , 21, 153);
	            zomctl.setAction('slither', 0, 10 , 26, 149);
	            zomctl.setAction('setzoom', 0, 10 , 26, 149);
	            zomctl.setZoomLimit(1, 18);

				_MacMap._mapMoveFirst = true;
                
				//イベントバインド
				var clbk = function(){
                    var newLoc = selfMap.getMapLocation();
					var newLon = newLoc.lon;
					var newLat = newLoc.lat;

					var oldLon = _MacMap._startCenterPoint.lon;
					var oldLat = _MacMap._startCenterPoint.lat;

					var diffLon = newLon - oldLon;
					var diffLat = newLat - oldLat;
					var length = Math.sqrt(diffLon * diffLon + diffLat * diffLat);

					var newScale = selfMap.getMapScale(); 
					var oldScale = _MacMap._startScale;
					var diffScale = newScale - oldScale;
				
		            if( newScale > 9){
                        $("#mapShopAround").css("display","none");
                    } else {
                        $("#mapShopAround").css("display","block");
                    }
					if( diffScale < 0 ) {
						_MacMap.search(new ZdcPoint(newLon, newLat), function() {
							_MacMap.display(null);
						});
                    } else if( length > 0.020 ) {
						//first time ignore
						if( _MacMap._mapMoveFirst) {
							_MacMap._mapMoveFirst = false;
							return;
						}
						_MacMap.search(new ZdcPoint(newLon, newLat), function() {
							_MacMap.display(null);
						});
                    }
				};

	            // イベント
				ZdcEvent.addListener(selfMap, "dragmapend", clbk);
				ZdcEvent.addListener(selfMap, "scrollmapend", clbk);
	            ZdcEvent.addListener(zomctl, "clickend", function() {
		        switch (this.actionid) {
			    case 'none':
				    break;
			    case 'zoomOut':
				    _MacMap._mapInstance.mapZoomOut();
				    this.setSlitherPosition();
	                clbk();
				    break;
			    case 'zoomIn':
				    _MacMap._mapInstance.mapZoomIn();
				    this.setSlitherPosition();
	                clbk();
				    break;
			    case 'setzoom':
				    var s = this.getZoom();
				    _MacMap._mapInstance.setMapScale(s);
				    this.setSlitherPosition();
	                clbk();
				    break;
		        }
	            });
	            ZdcEvent.addListener(zomctl, "mousedowngrid", function() {
		            if (this.actionid == 'slither') {
			            this.dragstart(1);
			            return false;
		            }
	            });
	            ZdcEvent.addListener(zomctl, "mouseup", function() {
		            if (this.actionid == 'slither') {
			            this.dragend();
	                    clbk();
		            }
	             });
			
				/* 地図コントロールを追加する */
	            selfMap.addUserZoomControl(zomctl, 20, 20);	//(doc, top, left);
	            zomctl.setSlitherPosition();

				_MacMap._firstSearch = false;
			}

			var msgWin = new ZdcUserMsgWindow();
			msgWin.setImage('/shared/graphic/blank.gif',new ZdcSize(1,1),'/shared/graphic/blank.gif',new ZdcSize(1,1),'/shared/graphic/blank.gif',new ZdcSize(1,1),null,null);
			//msgWin.setDocPosition(0,0,20,50,3,308,95,0);
			//msgWin.setTextClass("msgstyle");
 		    msgWin.setDocOffset(5,-225);
			//アイコンプロット
			var len;
			var markPointList = [];
			var list = _MacMap._shopList;
			
			_MacMap.determineOptions();

			if((len = list.length) > 0) {
				if(!_MacMap._layerInstance)
					return;
				for(var i = 0; i < len; i++) {
					var obj = list[i];
					if(_MacMap.searchMode & _MacMap.CONDITION_24) {
						if(obj.time_24h != "1")
							continue;
					}
					if(_MacMap.searchMode & _MacMap.CONDITION_PK) {
					    if(!obj.parking || obj.parking == 0) 
							continue;
					}
					if(_MacMap.searchMode & _MacMap.CONDITION_DT) {
						if(obj.drivethr != "1") 
							continue;
					}
					if(_MacMap.searchMode & _MacMap.CONDITION_DS) {
						if(obj.ds != "1")
							continue;
					}
					if(_MacMap.searchMode & _MacMap.CONDITION_BP) {
						if(obj.bp != "1")
							continue;
					}
					if(_MacMap.searchMode & _MacMap.CONDITION_PL) {
						if(obj.playland != "1")
							continue;
					}
					if(_MacMap.searchMode & _MacMap.CONDITION_AD) {
						if(obj.mcadvent != "1")
							continue;
					}
					if(_MacMap.searchMode & _MacMap.CONDITION_LS) {
						if(obj.ls != "1")
							continue;
					}
					if(_MacMap.searchMode & _MacMap.CONDITION_BF) {
						if(obj.bf != "1")
							continue;
					}
					
					var icon = new ZdcIcon();
					if(obj.gopen == "0") {
						icon.image = "/shop/map/shared/graphic/icon_map_shop_new.png";
						icon.offset = new ZdcPixel(-23,-66);
					}
					else {
						icon.image = "/shop/map/shared/graphic/icon_map_shop.png";
						icon.offset = new ZdcPixel(-23,-55);
					}

					var markPoint = new ZdcPoint(obj.longitude, obj.latitude);
					markPointList.push(markPoint);
					var mark = new ZdcMarker(markPoint, icon);
					mark.id = obj.strcode;
					mark.lon = obj.lon;
					mark.lat = obj.lat;
					mark.strname = obj.strname;
					mark.address = obj.address;
					if( obj.telno == null ) {
					    mark.telno = "";
                    } else {
					    mark.telno = obj.telno;
                    }

					//アイコンクリック->店舗詳細（吹き出し)表示
					//TODO:removeEventがらみのリーク懸念チェック
					
					//アイコンリスト作成
					var iconcnt = 0;
					var msgbgclass = 'ShopInfoLine1 png_bg';
					var iconlist = '<ul class="ShopInfoIcon">';
					if(obj.ds == "1") {
						iconlist += '<li><img src="/shop/map/shared/graphic/icon_shopinfo_ds.gif" alt="DS" width="40" height="40"></li>';
					    iconcnt++;
					}
					
					if(obj.parking && obj.parking > 0) {
						iconlist += '<li><img src="/shop/map/shared/graphic/icon_shopinfo_parking.gif" alt="駐車場" width="40" height="40"></li>';
					    iconcnt++;
					}
					if(obj.bf == "1") {
						iconlist += '<li><img src="/shop/map/shared/graphic/icon_shopinfo_morning.gif" alt="朝マック" width="40" height="40"></li>';
					    iconcnt++;
					}
					if(obj.drivethr == "1") {
						iconlist += '<li><img src="/shop/map/shared/graphic/icon_shopinfo_drivethrough.gif" alt="ドライブスルー" width="40" height="40"></li>';
					    iconcnt++;
					}
					if(obj.bp == "1") {
						iconlist += '<li><img src="/shop/map/shared/graphic/icon_shopinfo_birthday.gif" alt="バースデーパーティー" width="40" height="40"></li>';
					    iconcnt++;
					}
					if(obj.time_24h == "1") {
						iconlist += '<li><img src="/shop/map/shared/graphic/icon_shopinfo_24h.gif" alt="24時間営業" width="40" height="40"></li>';
					    iconcnt++;
					}
					if(obj.ls == "1") {
						iconlist += '<li><img src="/shop/map/shared/graphic/icon_shopinfo_over100.gif" alt="席数100以上" width="40" height="40"></li>';
					    iconcnt++;
					}
					if(obj.playland == "1") {
						iconlist += '<li><img src="/shop/map/shared/graphic/icon_shopinfo_playland.gif" alt="プレイランド" width="40" height="40"></li>';
					    iconcnt++;
					}
					iconlist += "</ul>";
					mark.iconlist = iconlist;
					if( iconcnt > 6 )
					    msgbgclass = 'ShopInfoLine2 png_bg';
					mark.msgbgclass = msgbgclass;

					ZdcEvent.addListener(mark, "mouseovermarker", function(){
						if(selfMap.usermsgopenstatus)
							selfMap.closeUserMsgWindow();
						this.icon.msgoffset.x = 0;
						this.icon.msgoffset.y = -0;
						this.openUserMsgWindow(msgWin, this.Point, $(
                        '<div class="'+this.msgbgclass+'">'+
			            '<dl class="ShopInfo">'+
				        '<dt><a href="/shop/map/map.php?strcode='+this.id +'" target="_blank">'+this.strname+'</a></dt>' +
				        '<dd><table border="0" cellspacing="0" cellpadding="0">' +
					    '<tr>' +
						     '<th><img src="/shop/map/shared/graphic/title_mapinfo_address.gif" alt="住所" width="50" height="17"></th>' +
						     '<td>'+this.address+'</td>' +
					        '</tr>' +
					        '<tr>' +
						        '<th><img src="/shop/map/shared/graphic/title_mapinfo_tel.gif" alt="電話" width="50" height="17"></th>' +
						        '<td>'+this.telno+'</td>' +
					        '</tr>' +
				        '</table>' +
				        '</dd>' +
			        '</dl>' +
					this.iconlist +
			        '<p class="CloseButton"><a href="javascript:McdTenpoMap._mapInstance.closeUserMsgWindow();"><img src="/shop/map/shared/graphic/icon_map_close.png" alt="閉じる" width="38" height="38"></a></p>' +
		        '</div>'
						).get(0), 3);
					});
					ZdcEvent.addListener(mark, "mouseclickmarker", function(){
						window.open("/shop/map/map.php?strcode="+this.id);
					})
					selfLayer.addMarker(mark);
				}
			}
			_MacMap._mapInstance = selfMap;
		},

		route:function(){
			selfMap = _MacMap._mapInstance;
		    $_macmap.parseQuery();
		    var queries = $_macmap.query;
			    var target = queries["target"];
			    var arrCoordinate = target.split(",");
			    var targetPoint = new ZdcPoint(arrCoordinate[1], arrCoordinate[0]);
			    var route, opts;
			    if(window.location.pathname.indexOf("printmap2") >= 0) {
	 			    route = new ZdcPRouteSearch();
	 			    opts = new ZdcPRouteSearchOptions();
	 			    opts.departurePoint.point = targetPoint;
	 			    opts.arrivalPoint.point = _MacMap._searchBasePoint;
	 			    opts.psc = '3';
	 			    opts.pointFlg = '1';
	 			    opts.stationFlg = '0';
	 			    opts.showMarker = false;
	 			    selfMap.addPRouteSearch(route);
			    }
			    else {
				    route = new ZdcRouteSearch();
				    opts = new ZdcRouteSearchOptions();
	 			    opts.departurePoint = targetPoint; 
 				    opts.departurePoint.stationFlg = '0';
	 			    opts.arrivalPoint = _MacMap._searchBasePoint;
				    opts.pointFlg = '1';
				    opts.showMarker = false;
			    
				    /* 探索終了後に実施する関数を指定する */
				    selfMap.addRouteSearch(route);
			    }
			    var scale = _MacMap._mapInstance.getMapBoxScale(new ZdcBox(_MacMap._searchBasePoint, targetPoint));
			    var difflat = Math.abs(_MacMap._searchBasePoint.lat - targetPoint.lat) / 2;
			    var difflon = Math.abs(_MacMap._searchBasePoint.lon - targetPoint.lon) / 2;
			    var minLat = Math.min(_MacMap._searchBasePoint.lat, targetPoint.lat);
			    var minLon = Math.min(_MacMap._searchBasePoint.lon, targetPoint.lon);
			
			    ZdcEvent.addListener(route, 'end', function(result){
				    if(result.status != '0') {
                        McdMessage.showError('zdcapi', 'apierror', 'other');
				    }
			    });

			    /* 探索を実施する */
		        route.search(opts);
		        _MacMap._mapInstance.setMapLocation(new ZdcPoint(minLon + difflon, minLat + difflat), scale);
		},
		saveCenterPoint : function() {
			selfMap = _MacMap._mapInstance;
			_MacMap._searchBasePoint = selfMap.getMapLocation();

		},
		determineOptions : function() {
			_MacMap.searchMode = 0;
			$("#refPk,#refDt,#refDs,#refBp,#refPl,#refAd,#refLs,#refBf,#ref24").each(function(n,e){
				if(e.checked) {
					_MacMap.searchMode |= e.value;
				}
			});

		}
		
	};
	window.McdTenpoMap = _MacMap;


	var _MacSMap = {
		parentId : "refineMap",
		searchmapId : "searchmap",
		railmapId : "railmap",
		htmlAreaId : "Area",
		htmlMapId : "Map",
		htmlRailId : "Rail",
		htmlSubRailId : "SubRail",
		query : null,
		commonInit : function() {
			_MacSMap.binds.refineMap();
            /* M 指定されてくる場合もあるので
			$("#refBk,#refDt,#refDs,#refBp,#refPl,#refAd,#refLs,#refBf,#ref24").each(function(n,e){
				e.checked = false;
			})
            */

		},
		parseQuery : function() {
			var idx = window.location.search.indexOf("?")
			var qs = window.location.search.substring(idx + 1);
			var queries = qs.split('&');
			var query = {};
			for(var i = 0,len = queries.length; i < len; ++i) {
				var tmps = queries[i].split("=");
				query[tmps[0]] = tmps[1];
			}
			_MacSMap.query = query;
		},
		delegates : {
			areaSelect : function (result) {
				var point = result.items[0].point;
				$("#refineMap").css("height","359px");
				if(!McdTenpoMap._firstSearch){
				    _MacMap._mapInstance.setMapLocation(point, 13);  // 1/10000
				    _MacMap._startScale = 13;
                		}
				$("#"+_MacSMap.htmlMapId).css({width:"525px",height:"353px"});
				McdTenpoMap.search(point, _MacSMap.delegates.areaSearchCallback);
				$("#mapBack").css("display", "block");
				$("#mapBack").click(function(){
					$("#refineMap").hide();
					$("#mapShopAround").hide();
					$("#"+_MacSMap.htmlMapId).css({display:"none"});
					$(this).hide();
					$("#"+_MacSMap.binds.switchFlashToJs).show();
				});
				
				$("#refineMap").get(0).ontouchstart = function(ev){ev.preventDefault();}
				$("#refineMap").get(0).ontouchmove = function(ev){ev.preventDefault();}


			},
			stationSelect : function (result) {
				var point = result.items[0].point
				McdTenpoMap.search(point, _MacSMap.delegates.areaSearchCallback);
				$("#mapBack").css("display", "block");
			},
			areaSearchCallback : function() {
				McdTenpoMap.display(null);
			}

		},
		models : {
		},
		views : {
			//都道府県の地図表示
			pref : function(id) {
				smap = new ZdcSearchMap();
				var opts = new ZdcSearchMapOptions();
				opts.todCode = id;
 				opts.callback = function(result){
 					_MacSMap.delegates.areaSelect(result);
 				}; // 検索終了時に呼ぶ関数を指定する */

                //data variables.
			    area = {
                    "01a": {"w" : "470", "h":"696"},
                    "01b": {"w" : "460", "h":"497"},
                    "02":  {"w" : "525", "h":"478"},
                    "03":  {"w" : "413", "h":"587"},
                    "04":  {"w" : "507", "h":"549"},
                    "05":  {"w" : "391", "h":"595"},
                    "06":  {"w" : "389", "h":"595"},
                    "02":  {"w" : "525", "h":"478"},
                    "03":  {"w" : "413", "h":"587"},
                    "04":  {"w" : "507", "h":"549"},
                    "05":  {"w" : "391", "h":"595"},
                    "06":  {"w" : "389", "h":"595"},
                    "07":  {"w" : "525", "h":"418"},
                    "08":  {"w" : "467", "h":"595"},
                    "09":  {"w" : "485", "h":"595"},
                    "10":  {"w" : "525", "h":"548"},
                    "11":  {"w" : "525", "h":"370"},
                    "12":  {"w" : "449", "h":"595"},
                    "13":  {"w" : "525", "h":"477"},
                    "14":  {"w" : "525", "h":"423"},
                    "15":  {"w" : "525", "h":"526"},
                    "16":  {"w" : "525", "h":"469"},
                    "17":  {"w" : "371", "h":"595"},
                    "18":  {"w" : "525", "h":"452"},
                    "19":  {"w" : "525", "h":"552"},
                    "20":  {"w" : "378", "h":"595"},
                    "21":  {"w" : "497", "h":"595"},
                    "22":  {"w" : "525", "h":"417"},
                    "23":  {"w" : "525", "h":"498"},
                    "24":  {"w" : "347", "h":"595"},
                    "25":  {"w" : "371", "h":"595"},
                    "26":  {"w" : "525", "h":"573"},
                    "27":  {"w" : "416", "h":"594"},
                    "28":  {"w" : "390", "h":"595"},
                    "29":  {"w" : "367", "h":"595"},
                    "30":  {"w" : "510", "h":"595"},
                    "31":  {"w" : "525", "h":"274"},
                    "32":  {"w" : "525", "h":"504"},
                    "33":  {"w" : "525", "h":"595"},
                    "34":  {"w" : "525", "h":"496"},
                    "35":  {"w" : "525", "h":"404"},
                    "36":  {"w" : "525", "h":"424"},
                    "37":  {"w" : "525", "h":"419"},
                    "38":  {"w" : "525", "h":"559"},
                    "39":  {"w" : "525", "h":"441"},
                    "40":  {"w" : "525", "h":"568"},
                    "41":  {"w" : "525", "h":"543"},
                    "42":  {"w" : "525", "h":"528"},
                    "43":  {"w" : "525", "h":"529"},
                    "44":  {"w" : "525", "h":"529"},
                    "45":  {"w" : "393", "h":"595"},
                    "46":  {"w" : "525", "h":"595"},
                    "47":  {"w" : "525", "h":"595"}
                };
			    $("#"+_MacSMap.htmlMapId).css({width:"1px",height:"1px"});
                
                $("#refineMap").css("height",area[id]["h"] + "px");
                $("#refineMap").show();
				$("#"+_MacSMap.binds.switchFlashToJs).hide();
				smap.addMap(document.getElementById(_MacSMap.htmlAreaId), opts); // レイヤに地域図検索を追加する
			    $("#"+_MacSMap.htmlAreaId).show();
                $("#mapBack").unbind('click');
				$("#mapBack").css("display", "block");
				$("#mapBack").click(function(){
                    smap.removeMap();
                    $("#mapShopAround").hide();
                    $("#refineMap").hide();
                    $(this).hide();
                    // $("#"+_MacSMap.binds.switchFlashToJs).show();
					$(_MacMapAreaChoose.activeId).css({"display":"block"});
                    });
				
				
			},
			rail : function(id) {
				var rmap;
				rmap = new ZdcSearchRailwayMap();
			   	var opts = new ZdcSearchRailwayMapOptions();
			   	opts.mapNo = id; // 路線図の範囲を東京周辺にする
			   	opts.width = 537;
			   	opts.height = 380;
			   	opts.callback = function(result){
 					_MacSMap.delegates.stationSelect(result);
				}; // 検索終了時に呼ぶ関数を指定する
			   	rmap.addMainMap(document.getElementById(_MacSMap.htmlRailId), opts); // レイヤに路線図検索を追加する
			   	//rmap.addSubMap (document.getElementById(_MacSMap.htmlSubRailId)); // レイヤに路線図検索を追加する
				$("#mapBack").css("display", "block");
			    

			}
		},
		binds : {
			switchFlashToJs : "MapFlash",
			refineMap : function() {
				$("#refPk,#refDt,#refDs,#refBp,#refPl,#refAd,#refLs,#refBf,#ref24").click(function(e) {
					//すでにプロット済みなら絞り込み。
					if($("#"+_MacSMap.htmlMapId).css("display") == "block" && McdTenpoMap._shopList != null) {
						McdTenpoMap.display(null);
					}
				});
			}
		}
	};
	window.$_macmap = _MacSMap;

	//ページ初期化
	if(window.location.pathname.indexOf("railway") >= 0) {
		$(function(){
			$_macmap.commonInit();
		    $_macmap.parseQuery();
		    var queries = $_macmap.query;
			if(queries["rail_id"].length != 1 
                || !queries["rail_id"].match(/[1234567]/g)){
                McdMessage.showAlert("表示したい路線を正しく指定してください");
                return false;
            }
			//都市のIDを特定
			$_macmap.views.rail(queries["rail_id"]);

		});
    } else if(
			window.location.pathname.indexOf("map.php") >= 0 ||
			window.location.pathname.indexOf("printmap") >= 0 ) {
		$_macmap.parseQuery();
		var queries = $_macmap.query;
		if(queries["strcode"]) {
			var strPoint = window._MacStorePoint;
			var pArr = strPoint.split(",");
			var targetPoint = new ZdcPoint(pArr[1], pArr[0]);
			McdTenpoMap._isPageDetail = true;
		    $(function(){
			McdTenpoMap.search(targetPoint, function() {
				McdTenpoMap.display(null, null);
				if(window.location.pathname.indexOf("printmap") >= 0) {
                    if(typeof queries["target"] !="undefined"){
					    //route
					    McdTenpoMap.route();
                    }
                    return;
				}
				var kakudai = function(){
					$("#kakushuku").unbind();
					$("#kakushuku").click(function(){
						$("#mainInfo").fadeOut("slow",function(){
					        $("#accessMap").css({ float: "none" });
							$("#mainInfo2").slideDown("slow", function(){
                                $("#kakushuku").css({ left:"614px", display:"none" });
                                $("#kakushuku img").attr("src", "/shop/map/shared/graphic/button_map_small.png");
								$("#accessMap").animate({width:748});
								$("#Map").animate({width:748},function(){
									var map = McdTenpoMap._mapInstance;
									map.resizeMapWindow(0,0,748,360);
									map.scrollToCenter(map.getMapLocation());
									map.reflashMap();
                                    $("#kakushuku").css({display:"block"});
								});
								shukushou();
							});
						});
					});
				};
				
				var shukushou = function() {
					$("#kakushuku").unbind();
					$("#kakushuku").click(function(){
						$("#accessMap").animate({width:374},function(){
                            $("#kakushuku").css({left:"240px", display:"none"});
                            $("#kakushuku img").attr("src", "/shop/map/shared/graphic/button_map_large.png");
							$("#mainInfo2").slideUp("slow",function(){
				                $("#accessMap").css({ float: "left" });
								$("#mainInfo").fadeIn("slow",function(){
									kakudai();
								});
							});
						});
						$("#Map").animate({width:374},function(){
							var map = McdTenpoMap._mapInstance;
							map.resizeMapWindow(0,0,374,359);
							map.scrollToCenter(map.getMapLocation());
							map.reflashMap();
                            $("#kakushuku").css({display:"block"});
						});
					})
				};
				kakudai();
			});
		    });
        }
	} else {
		$(function(){
			$_macmap.commonInit();
            McdTempoAreaMap = function(code){
				$_macmap.views.pref(code);
            };
		});
    }
})();

