function unload(){
	GUnload();
}

var Global = this;

var icon_fix_image = new Image();
icon_fix_image.src = "/contents/images/default/space/map_marker_fix.png";
var icon_fix = new GIcon();
icon_fix.image = icon_fix_image.src;
icon_fix.shadow = "/contents/images/default/space/map_marker_shadow.png";
icon_fix.iconSize = new GSize(30, 51);
icon_fix.shadowSize = new GSize(56, 51);
icon_fix.iconAnchor = new GPoint(13, 51);
icon_fix.infoWindowAnchor = new GPoint(13, 3);
icon_fix.infoShadowAnchor = new GPoint(27, 38);

var icon_unfix_image = new Image();
icon_unfix_image.src = "/contents/images/default/space/map_marker_unfix.png";
var icon_unfix = new GIcon();
icon_unfix.image = icon_unfix_image.src;
icon_unfix.shadow = "/contents/images/default/space/map_marker_shadow2.png";
icon_unfix.iconSize = new GSize(24, 36);
icon_unfix.shadowSize = new GSize(50, 36);
icon_unfix.iconAnchor = new GPoint(9, 34);
icon_unfix.infoWindowAnchor = new GPoint(9, 2);
icon_unfix.infoShadowAnchor = new GPoint(18, 19);

//マーカー固定ボタン
function MyFixControl() {}
MyFixControl.prototype = new GControl();
MyFixControl.prototype.initialize = function(map){
			var btnFix = $("btnFix");
			GEvent.addDomListener(btnFix, "click", function() {
				if(Global.map().markerCacheGT && Global.map().markerDraggable){
					Global.map().showMarker(Global.map().markerCacheGT.getPoint().lat(), Global.map().markerCacheGT.getPoint().lng(), 'fix');
				}
			});
			map.getContainer().appendChild(btnFix);
			return btnFix;
}
MyFixControl.prototype.getDefaultPosition = function(){
	return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(5, 20));
}

//マーカー固定解除ボタン
function MyUnfixControl() {}
MyUnfixControl.prototype = new GControl();
MyUnfixControl.prototype.initialize = function(map){
			var btnUnFix = $("btnUnFix");
			GEvent.addDomListener(btnUnFix, "click", function() {
				if(Global.map().markerCacheGT && !Global.map().markerDraggable){
					Global.map().showMarker(Global.map().markerCacheGT.getPoint().lat(), Global.map().markerCacheGT.getPoint().lng(), 'unfix');
					GEvent.trigger(Global.map().map,"moveend");
				}
			});
			map.getContainer().appendChild(btnUnFix);
			return btnUnFix;
}
MyUnfixControl.prototype.getDefaultPosition = function(){
	return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(110, 20));
}

//myplMapList(リスト)クラス
var myplMapList = Class.create();
myplMapList.prototype = {
	initialize: function(lat, lng, zoom, map_type, map_case, img_path){
		if(img_path == undefined)img_path = "default";
		if (GBrowserIsCompatible()) {
			this.mapElement = $("gmap");
			this.markerDraggable = false;
			this.shopOnThreadMap = false;
			this.shop_list = new Array();
			this.thread_list = new Array();
			this.map_case = map_case;
			this.map_type = map_type;
			this.img_path = img_path;
			this.markerCache = {};
			this.markerHtmlCache = {};
			this.map = new GMap2(this.mapElement);
			this.map.addControl(new GLargeMapControl());
			this.map.addControl(new GMapTypeControl());
			var overviewControl = new GOverviewMapControl(new GSize(150, 150));
			this.map.addControl(overviewControl);
			overviewControl.hide();
			this.map.setCenter(new GLatLng(lat, lng), zoom);
			if(0 <= map_type && map_type < 3){
				this.map.setMapType(G_DEFAULT_MAP_TYPES[map_type]);
			}
			this.map.enableDoubleClickZoom();
			this.map.enableContinuousZoom();
			if( map_case=='shop'){
				GEvent.addListener(this.map, "moveend", this.onMoveShop.bind(this));
			}else if( map_case=='thread'){
				GEvent.addListener(this.map, "moveend", this.onMoveThread.bind(this));
				this.map.addControl(new MyThreadEntryControl());
			}else if( map_case=='fleamarket'){
				GEvent.addListener(this.map, "moveend", this.onMoveFleamarket.bind(this));
			}
			overRide_Gmap_maptype_getMaximumResolution(this.map);
		}else{
		    $('notice').innerHTML += 'ご利用の環境では、Google Mapsが利用できません。';
		}
    },
	addMarker: function(lat, lng, id, icon, tip){
		if(!this.markerCache[id]){
			var marker = new GMarker(new GLatLng(lat, lng), {icon:icon,title:tip});
			GEvent.addListener(marker, "click", this.setMarkerHtml.bind(this, id));
			this.map.addOverlay(marker);
		    this.markerCache[id] = marker;
		}
	},
    setMarkerHtml: function(id){
    	if(this.markerHtmlCache[id]){
		    this.markerCache[id].openInfoWindowHtml(this.markerHtmlCache[id]);
    	}
    },
    showMapInfo: function(){
		//$('this_url').innerHTML = $("site_url").value + "space/maps?lat=" + this.map.getCenter().y + '&lng=' + this.map.getCenter().x + '&zoom=' + this.map.getZoom();
		//var bounds = this.map.getBounds();
	    //$('notice').innerHTML = '[Center]    lat:' + this.map.getCenter().y + '  lng:' + this.map.getCenter().x + '<br />';
	    //$('notice').innerHTML += '[NorthEast] lat:' + bounds.getNorthEast().lat() + '  lng:' + bounds.getNorthEast().lng() + '<br />';
	    //$('notice').innerHTML += '[SouthWest] lat:' + bounds.getSouthWest().lat() + '  lng:' + bounds.getSouthWest().lng() + '<br />';
    },
    onMoveThread: function(){
		$('th_entry_form').lat.value = this.map.getCenter().y;
		$('th_entry_form').lng.value = this.map.getCenter().x;
		$('th_entry_form').z.value = this.map.getZoom();
	    this.getThreadOnMapPoint();
	    if(this.shopOnThreadMap) this.getShopOnMapPoint(1);
	    if(this.fleamarketOnThreadMap) this.getFleamarketOnMapPoint(1);
	    this.getThreadOnMapLatest();
    },
    onMoveShop: function(){
	    this.getShopOnMapPoint(this.map_type);
    },
    onMoveFleamarket: function(){
	    this.getFleamarketOnMapPoint(this.map_case);
    },
    removeShopPoint: function(){
    	this.initShopPoint();
		this.shopOnThreadMap = false;
    },
    removeFleamarketPoint: function(){
    	this.initFleamarketPoint();
		this.fleamarketOnThreadMap = false;
    },
    initShopPoint: function(){
		for(i=0;i<this.shop_list.length;i++){
			var sid = this.shop_list[i];
			var marker = this.markerCache[sid];
			if(marker) marker.remove();
			this.markerCache[sid] = null;
			this.markerHtmlCache[sid] = null;
		}
		this.shop_list = new Array();
    },
	getShopOnMapPoint: function(map_type){
		var options = {
			method : 'get',
			onFailure: function() { alert("通信エラー"); },
			onComplete: function(res) {
				if(this.shop_list.length > 600){
					this.initShopPoint();
				}
				var obj = eval('(' + res.responseText + ')');
				var icon = new GIcon();
				icon.shadow = "/contents/images/default/map/mm_sh_shadow.png";
				icon.iconSize = new GSize(16, 24);
				icon.shadowSize = new GSize(30, 24);
				icon.iconAnchor = new GPoint(6, 20);
				icon.infoWindowAnchor = new GPoint(5, 1);

				for(i=0;i<obj.result.length;i++){
					hid = obj.result[i].hid;
					id = 'sh' + obj.result[i].id;
					id4url = my_uZeroPadding(obj.result[i].id,11);
					title = '[' + obj.result[i].sub_str + '] ' + obj.result[i].name;
					ttype = obj.result[i].cat_id;
					cat_str = obj.result[i].cat_str;
					cat_id = obj.result[i].cat_id;
					sub_str = obj.result[i].cat_str;
					b_flg = obj.result[i].b_flg;
					dpr = obj.result[i].dpr;
					timg = obj.result[i].timg;
					lat = obj.result[i].lat;
					lng = obj.result[i].lng;
					icon.image = "/contents/images/default/map/mm_sh" + cat_id + ".png";
					this.addMarker(lat, lng, id, icon, title);
					if(!this.markerHtmlCache[id]){
						this.shop_list.push(id);
						var tempHtml = '';
						if( timg!= '' ){
							if(map_type==0){
								tempHtml = 
								'<div style="width:400px"><p><strong>' + title + '</strong></p><table><tr><td><img src=\'' + $('thread_image_url_base').value + 'shopi/' + timg + '.s?i=' + $('fw_passcode').value + '\' alt=\'' + title + '\' /></td><td style="padding:5px"><p>' + dpr + '&nbsp;&nbsp;&nbsp;<a href="/shop/' + id4url + '/?hid=' + hid + '">詳細を見る</a></p></td></tr></table></div>';
							}else{
								tempHtml = '<div style="width:400px"><p><strong>ショップ情報　' + title + '</strong></p><table><tr><td><img src=\'' + $('thread_image_url_base').value + 'shopi/' + timg + '.s?i=' + $('fw_passcode').value + '\' alt=\'' + title + '\' /></td><td style="padding:5px"><p>' + dpr + '&nbsp;&nbsp;&nbsp;<a href="/shop/' + id4url + '/?hid=' + hid + '">詳細を見る</a></p></td></tr></table></div>';
							}
						}else{
							if(map_type==0){
								tempHtml = '<div style="width:400px"><p><strong>' + title + '</strong></p><p>' + dpr + '</p><p><a href="/shop/' + id4url + '/?hid=' + hid + '">詳細を見る</a></p></div>';
							}else{
								tempHtml = '<div style="width:400px"><p><strong>ショップ情報　' + title + '</strong></p><p>' + dpr + '</p><p><a href="/shop/' + id4url + '/?hid=' + hid + '">詳細を見る</a></p></div>';
							}
						}
					    this.markerHtmlCache[id] = tempHtml;
					}
				}
			}.bind(this)
		};
		var lat = this.map.getCenter().y;
		var lng = this.map.getCenter().x;
		var bounds = this.map.getBounds();
		var nelat = bounds.getNorthEast().lat();
		var nelng = bounds.getNorthEast().lng();
		var swlat = bounds.getSouthWest().lat();
		var swlng = bounds.getSouthWest().lng();
		if(map_type==0){
			var cid = $('map_cid').value;
			var sid = $('map_sid').value;
			var cnt = $('map_cnt').value;
			var kw = $('map_kw').value;
			new Ajax.Request('/shop/get_shop_map.js?cid=' + cid  + '&sid=' + sid + '&cnt=200&kw=' + kw + '&lat=' + lat + '&lng=' + lng + '&nelat=' + nelat + '&nelng=' + nelng + '&swlat=' + swlat + '&swlng=' + swlng  + '&rd=' + (new Date).getTime(), options);
		}else{
			this.shopOnThreadMap = true;
			new Ajax.Request('/shop/get_shop_map.js?&cnt=100&lat=' + lat + '&lng=' + lng + '&nelat=' + nelat + '&nelng=' + nelng + '&swlat=' + swlat + '&swlng=' + swlng  + '&rd=' + (new Date).getTime(), options);
		}
	}
}

//myplMapクラス
var myplMap = Class.create();
myplMap.prototype = {
	initialize: function(lat, lng, zoom, map_type){
		if (GBrowserIsCompatible()) {
			this.mapElement = $("gmap");
			this.markerDraggable = false;
			this.map = new GMap2(this.mapElement);
			this.map.setCenter(new GLatLng(lat, lng), zoom);
			if(0 <= map_type && map_type < 3){
				this.map.setMapType(G_DEFAULT_MAP_TYPES[map_type]);
			}
			overRide_Gmap_maptype_getMaximumResolution(this.map);
		}else{
		    $('notice').innerHTML += 'ご利用の環境では、Google Mapsが利用できません。';
		}
    },
	addMarker: function(lat, lng, id, ttype, ic, tip){
		var icon = new GIcon();
		icon.image = "/contents/images/default/map/mm_" + ic + ttype + ".png";
		icon.shadow = "/contents/images/default/map/mm_shl_shadow.png";
		icon.iconSize = new GSize(30, 45);
		icon.shadowSize = new GSize(60, 48);
		icon.iconAnchor = new GPoint(15, 43);
		icon.infoWindowAnchor = new GPoint(5, 1);
		var marker = new GMarker(new GLatLng(lat, lng), {icon:icon,title:tip});
		this.map.addOverlay(marker);
	},
	addMarkerFix: function(lat, lng, id, tip){
		var marker = new GMarker(new GLatLng(lat, lng), {icon:icon_fix,title:tip});
		this.map.addOverlay(marker);
	},
	addStandardControl: function(){
		this.map.addControl(new GLargeMapControl());
		this.map.addControl(new GMapTypeControl());
	},
	addSmallControl: function(){
		this.map.addControl(new GSmallMapControl());
		this.map.addControl(new GMapTypeControl());
	},
	disableDrag: function(){
		this.map.disableDragging();
	}	
}

//汎用Mapクラス
var commonMap = Class.create();
commonMap.prototype = {
	initialize: function(lat, lng, zoom, map_type){
		if (GBrowserIsCompatible()) {
			this.mapElement = $("gmap");
			this.map = new GMap2(this.mapElement);
			this.markerCache = {};
			this.markerHtmlCache = {};
			this.map.setCenter(new GLatLng(lat, lng), zoom);
			if(0 <= map_type && map_type < 3){
				this.map.setMapType(G_DEFAULT_MAP_TYPES[map_type]);
			}
			overRide_Gmap_maptype_getMaximumResolution(this.map);
		}else{
		    $('notice').innerHTML += 'ご利用の環境では、Google Mapsが利用できません。';
		}
    },
	addMarker: function(lat, lng, id, html, icon, tip){
		if(tip == undefined)tip = '';
		var marker = new GMarker(new GLatLng(lat, lng), {icon:icon,title:tip});
		GEvent.addListener(marker, "click", this.setMarkerHtml.bind(this, id));
		this.markerCache[id] = marker;
		this.markerHtmlCache[id] = html;
		this.map.addOverlay(marker);
	},
    setMarkerHtml: function(id){
    	if( this.markerHtmlCache[id] && this.markerHtmlCache[id]!='' ){
		    this.markerCache[id].openInfoWindowHtml(this.markerHtmlCache[id]);
    	}
    },
	addStandardControl: function(){
		this.map.addControl(new GLargeMapControl());
		this.map.addControl(new GMapTypeControl());
	},
	disableDrag: function(){
		this.map.disableDragging();
	},
	addTopEntry: function(){
		this.map.addControl(new TopEntryControl());
	}
}

//telShopMapクラス
var telShopMap = Class.create();
telShopMap.prototype = {
	initialize: function(lat, lng, zoom, map_type){
		if (GBrowserIsCompatible()) {
			this.mapElement = $("gmap");
			this.markerDraggable = false;
			this.map = new GMap2(this.mapElement);
			this.map.setCenter(new GLatLng(lat, lng), zoom);
			this.markerCache = {};
			this.markerHtmlCache = {};
			if(0 <= map_type && map_type < 3){
				this.map.setMapType(G_DEFAULT_MAP_TYPES[map_type]);
			}
			overRide_Gmap_maptype_getMaximumResolution(this.map);
		}else{
		    $('notice').innerHTML += 'ご利用の環境では、Google Mapsが利用できません。';
		}
    },
	addMarker: function(lat, lng, id, ttype, tip, add, tel){
		var icon = new GIcon();
		icon.image = "/contents/images/default/map/mm_" + "sh" + ttype + ".png";
		icon.shadow = "/contents/images/default/map/mm_sh_shadow.png";
		icon.iconSize = new GSize(16, 24);
		icon.shadowSize = new GSize(30, 24);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		var marker = new GMarker(new GLatLng(lat, lng), {icon:icon,title:tip});
		this.map.addOverlay(marker);
		var tempHtml = '<div><p><strong>' + tip + '</strong></p><p>' + add + '</p><p>' + tel + '</p></div>';
		GEvent.addListener(marker, "click", function(){ this.openInfoWindowHtml(tempHtml); });
		this.markerCache[id] = marker;
		this.markerHtmlCache[id] = tempHtml;
	},
	addMarkerFix: function(lat, lng, id, tip){
		var marker = new GMarker(new GLatLng(lat, lng), {icon:icon_fix,title:tip});
		this.map.addOverlay(marker);
	},
	addStandardControl: function(){
		this.map.addControl(new GLargeMapControl());
		this.map.addControl(new GMapTypeControl());
	},
	showTooltip: function(id){
		if(this.markerCache[id]){
			var marker = this.markerCache[id];
			marker.openInfoWindowHtml(this.markerHtmlCache[id]);
		}
	},
	disableDrag: function(){
		this.map.disableDragging();
	}
}

//スポットクラス
var ShopSpotMap = Class.create();
ShopSpotMap.prototype = {
	initialize: function(lat, lng, zoom, map_type){
		if (GBrowserIsCompatible()) {
			this.shop_list = new Array();
			this.shop_no_list = new Array();
			this.markerCache = {};
			this.mapElement = $("gmap");
			this.markerDraggable = false;
			this.map = new GMap2(this.mapElement);
			this.map.setCenter(new GLatLng(lat, lng), zoom);
			this.map.addControl(new GLargeMapControl());
			this.map.addControl(new GMapTypeControl());
			this.map.addControl(new GScaleControl());
			this.map.enableDoubleClickZoom();
			this.map.enableContinuousZoom();
			GEvent.addListener(this.map, "moveend", this.onMoveSpot.bind(this));
			this.map.addControl(new ShopSpotOnMapSearchButton());
			
			//とりあえず1kmと10kmに円を描いてみる
			var circle1 = pseudoGCircle(new google.maps.LatLng(lat, lng), 0.1, "#FF0000", 1);
			this.map.addOverlay(circle1);
			var circle3 = pseudoGCircle(new google.maps.LatLng(lat, lng), 0.3, "#FF0099", 1);
			this.map.addOverlay(circle3);
			var circle5 = pseudoGCircle(new google.maps.LatLng(lat, lng), 0.5, "#FF6600", 1);
			this.map.addOverlay(circle5);
			var circle10 = pseudoGCircle(new google.maps.LatLng(lat, lng), 1, "#3366FF", 1);
			this.map.addOverlay(circle10);
			var circle20 = pseudoGCircle(new google.maps.LatLng(lat, lng), 2, "#993399", 1);
			this.map.addOverlay(circle20);
			//ここまで
			overRide_Gmap_maptype_getMaximumResolution(this.map);
		}else{
			$('notice').innerHTML += 'ご利用の環境では、Google Mapsが利用できません。';
		}
	},    
	addMarker: function(lat, lng, id, hid, cname, title, dpr, img_id, cid, no){
		if(lat<1) return;
		var icon = new GIcon();
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		if(no <= 20){
			this.shop_no_list[id] = 1;
			icon.iconSize = new GSize(24, 35);
			icon.shadowSize = new GSize(37, 34);
			icon.shadow = "/contents/images/default/map/shadow50.png";
			icon.image = "/contents/images/default/map/mm_noo" + no + ".png";
		}else{
			this.shop_list.push(id);
			icon.iconSize = new GSize(16, 24);
			icon.shadowSize = new GSize(30, 24);
			icon.shadow = "/contents/images/default/map/mm_sh_shadow.png";
			icon.image = "/contents/images/default/map/mm_sh" + cid + ".png";
		}
		var marker = new GMarker(new GLatLng(lat, lng), {icon:icon,title:title});
		GEvent.addListener(marker, "click", this.setMarkerHtml.bind(this, id, hid, cname, title, dpr, img_id));
		this.map.addOverlay(marker);
		if(!this.markerCache[id])this.markerCache[id] = marker;
	},
	setMarkerHtml: function(id, hid, cname, title, dpr, img_id){
		var s_id = id;
		if(id.length>2){
			s_id = id.substr(2,id.length);
		}
		var id4url = my_uZeroPadding(s_id,11);
		var tempHtml = '';		
		if(img_id > 0){
			tempHtml = '<div style="width:400px"><p>' + cname + '&nbsp;<span class="clr_03"><strong>' + title + '</strong></span></p>';
			tempHtml += '<table class="fontS"><tr><td><img src=\'' + $('thread_image_url_base').value + 'shopi/' + img_id + '.top?i=' + $('fw_passcode').value + '\' alt=\'' + title + '\' /></td>';
			tempHtml += '<td style="padding:5px"><p>' + dpr + '</p';
			tempHtml += '<p class="alnR"><a href="/shop/' + id4url + '/?hid=' + hid + '" class="linkmark_01">詳細を見る</a></p></td></tr></table></div>';
		}else{
			if(hid > 0){
				tempHtml = '<div style="width:400px"><p>' + cname + '&nbsp;<span class="clr_03"><strong>' + title + '</strong></span></p>';
				tempHtml += '<p class="fontS">' + dpr + '</p><p class="fontS alnR"><a href="/shop/' + id4url + '/?hid=' + hid + '" class="linkmark_01">詳細を見る</a></p></div>';
			}else{
				tempHtml = '<div style="width:250px"><p>' + cname + '&nbsp;<span class="clr_03"><strong>' + title + '</strong></span></p>';
				tempHtml += '<p class="fontS">' + dpr + '</p></div>';
			}
		}
		var marker = this.markerCache[id];
		marker.openInfoWindowHtml(tempHtml);
	},
	initShopPoint: function(){
		for(i=0;i<this.shop_list.length;i++){
			var sid = this.shop_list[i];
			var marker = this.markerCache[sid];
			if(marker) marker.remove();
			this.markerCache[sid] = null;
		}
		this.shop_list = new Array();
	},
	onMoveSpot: function(){
		this.getSpotOnMapPoint();
	},
	getSpotOnMapPoint: function(){
		var fm = $('search_on_map_form');
		var options = {
			method : 'post',
			postBody : Form.serialize(fm),
			onFailure: function() { alert("通信エラー"); },
			onComplete: function(res) {
				if(this.shop_list.length>100){
					this.initShopPoint();
				}
				var obj = eval('(' + res.responseText + ')');
				for(i=0;i<obj.result.length;i++){
					lat = obj.result[i].lat;
					lng = obj.result[i].lng;
					id = 'sh' + obj.result[i].id;
					hid = obj.result[i].hid;
					cname = '[' + obj.result[i].cat_str + '｜' + obj.result[i].sub_str + ']';
					title = obj.result[i].name;
					dpr = obj.result[i].dpr;
					timg = obj.result[i].timg;
					cat_id = obj.result[i].cat_id;
					if(!this.shop_no_list[id]){
						this.addMarker(lat, lng, id, hid, cname, title, dpr, timg, cat_id, 50);
					}					
				}
			}.bind(this)
		};
		var lat = this.map.getCenter().y;
		var lng = this.map.getCenter().x;
		$('spot_on_map_lat').value = lat;
		$('spot_on_map_lng').value = lng;
		$('spot_on_map_zoom').value = this.map.getZoom();
		new Ajax.Request('/shop/spot.js', options);
	}
}
//スポット再検索ボタン
function ShopSpotOnMapSearchButton () {}
ShopSpotOnMapSearchButton.prototype = new GControl();
ShopSpotOnMapSearchButton.prototype.initialize = function(map){
	var btnThEntry = $("search_on_map");
	map.getContainer().appendChild(btnThEntry);
	return btnThEntry;
}
ShopSpotOnMapSearchButton.prototype.getDefaultPosition = function(){
	return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(15, 15));
}


//擬似円描画関数 << http://www.nanchatte.com/map/circle.html >>
/**
 * pseudoGCircle （擬似-円描画）
 * @param point   中心地 google.maps.LatLng
 * @param radius  半径 km
 * @param color   google.maps.Polylineに渡される（省略可）
 * @param weight  google.maps.Polylineに渡される（省略可）
 * @param opacity google.maps.Polylineに渡される（省略可） 
 * @return google.maps.Polyline
 */
function pseudoGCircle(point, radius, color, weight, opacity) {
  var vertex = 360;               // 頂点の数
  var EquatorialRadius = 6378137; // 赤道半径 (WGS-84)
  var F = 298.257223563;          // 扁平率の逆数 (WGS-84)

  // 離心率の２乗
  var E = ((2 * F) -1) / Math.pow(F, 2);

  // π × 赤道半径
  var PI_ER = Math.PI * EquatorialRadius;

  // 1 - e^2 sin^2 (θ)
  var TMP = 1 - E * Math.pow(Math.sin(point.latRadians()), 2);

  // 経度１度あたりの長さ(m)
  var arc_lat = (PI_ER * (1 - E)) / (180 * Math.pow(TMP, 3/2)); 

  // 緯度１度あたりの長さ(m)
  var arc_lng = (PI_ER * Math.cos(point.latRadians())) / (180 * Math.pow(TMP, 1/2)); 

  // 半径をｍ単位に
  var R = radius * 1000;

  var points = new Array(vertex);
  for (i = 0; i <= vertex; i++) {
    var rad = (i / (vertex / 2)) * Math.PI;
    var lat = (R / arc_lat) * Math.sin(rad) + point.lat();
    var lng = (R / arc_lng) * Math.cos(rad) + point.lng();
    points[i] = new google.maps.LatLng(lat, lng);
  }
  return new google.maps.Polyline(points, color, weight, opacity);
}

function overRide_Gmap_maptype_getMaximumResolution(gmap){
	var maptypes = gmap.getMapTypes();
	for(var i = 0; i < maptypes.length; i++){
		if( (maptypes[i].uc && maptypes[i].uc == 'm') || (maptypes[i].mT && maptypes[i].mT == 'm') ){
			maptypes[i].getMaximumResolution = function(){
				return 20;
			};
			continue;
		}
	}
}