/*********************************************************/
/* 서유석(Yooseok seo) 2009.09.24 http://www.dearmap.com */
/*********************************************************/

function tools_control_clear() {
	if(distance_control) distance_control.clear();
	if(area_control) area_control.clear();
	if(direction_control) direction_control.clear();
	if(streetview_control) streetview_control.clear();
	if(weather_control) weather_control.clear();
	if(elevation_control) elevation_control.clear();
}

//---------------------
// 거리 측정 도구
//---------------------
function DistanceControl(opt) {
	this.opt = opt ? opt : {};
}
DistanceControl.prototype = new GControl();
DistanceControl.prototype.initialize = function(map) {
	var me = this;
	me.markers = [];
	me.poly = null;
	me.labels = [];

	me.icon = new GIcon(G_DEFAULT_ICON);
	me.icon.image = "/img/map_overlay_handle_off.gif";
	me.icon.iconSize = new GSize(11,11);
	me.icon.shadowSize = new GSize(0,0);
	me.icon.iconAnchor = new GPoint(6,8);

	this.container = document.createElement("div");
	this.container.style.border = "1px solid #000";
	this.div = document.createElement("div");
	this.div.title = array_lang['805'];
	this.div.className = 'gbutton';
	this.container.appendChild(this.div);
	this.div.appendChild(document.createTextNode(array_lang['805']));

	GEvent.addDomListener(this.div, "click", function() {
		if(this.style.fontWeight == 'bold') {
			me.clear();
		}
		else {
			if(area_control) area_control.clear();
			if(direction_control) direction_control.clear();
			if(streetview_control) streetview_control.clear();
			if(weather_control) weather_control.clear();
			if(elevation_control) elevation_control.clear();

			this.style.fontWeight = 'bold';
			this.style.color = '#FF0000';
			this.innerHTML = array_lang['30'];

			var ll = map.getBounds().getNorthEast();
			me.label = new ELabel(ll,array_lang['143'],null,new GSize(15,8)); // 지도를 클릭하세요.
			map.addOverlay(me.label);

			me.map_mousemove_listener = GEvent.addListener(map, 'mousemove', function(latlng) { // http://esa.ilmari.googlepages.com/mymapsmarker.htm
				me.label.setLatLng(latlng);
			});
			me.poly = new GPolyline([],'#0000FF',2,0.7);
			map.addOverlay(me.poly);

			me.poly.enableDrawing();
			//me.poly.enableEditing({onEvent: 'mouseover'});
			//me.poly.disableEditing({onEvent: 'mouseout'});

			GEvent.addListener(me.poly, 'endline', function(ll, index) {
				if(me.label) map.removeOverlay(me.label);
			});
			GEvent.bind(me.poly, "lineupdated", null, function() {
				var n = me.poly.getVertexCount();
				var s = array_lang['857']; // 시작
				if(n > 1) {
					//var p = new GPolyline([this.getVertex(n-2),this.getVertex(n-1)],'#0000FF',1,0.1); // 각각의 거리
					//var p = new GPolyline([this.getVertex(0),this.getVertex(n-1)],'#0000FF',1,0.1); // 시작점부터의 거리
					s = poly2length(me.poly);
				}
				var label = new ELabel(me.poly.getVertex(n-1),s,{color:'#FFFFFF',fill_color:'#CC0000',line_color:'#930000'});
				map.addOverlay(label);
				me.labels.push(label);

				if(n >= 2) me.label.setContents(array_lang['144']); // 끝내려면 마지막 지점 클릭
				//me.show();
			});
			me.label.setContents(array_lang['143']);
		}
	});
	map.getContainer().appendChild(this.container);
	return this.container;
}
DistanceControl.prototype.getDefaultPosition = function() {
	var x = this.opt.x ? this.opt.x : 265;
	var y = this.opt.y ? this.opt.y : 7;
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(x,y));
}
DistanceControl.prototype.clearListeners = function() {
	if(this.map_mousemove_listener) GEvent.removeListener(this.map_mousemove_listener);
	if(this.map_click_listener) GEvent.removeListener(this.map_click_listener);
}
DistanceControl.prototype.clearMarkers = function() {
	if(this.poly) {
		this.poly.disableEditing();
		map.removeOverlay(this.poly);
	}
	if(this.label) map.removeOverlay(this.label);
	for(var i in this.markers) map.removeOverlay(this.markers[i]);
	for(var i in this.labels) map.removeOverlay(this.labels[i]);
	this.markers = [];
	this.labels = [];
}
DistanceControl.prototype.clear = function() {
	this.clearListeners();
	this.clearMarkers();
	this.div.style.fontWeight = 'normal';
	this.div.style.color = '#000000';
	this.div.innerHTML = array_lang['805'];
}

//---------------------
// 면적 측정 도구
//---------------------
function AreaControl(opt) {
	this.opt = opt ? opt : {};
}
AreaControl.prototype = new GControl();
AreaControl.prototype.initialize = function(map) {
	var me = this;
	me.poly = null;
	me.label = null;

	this.container = document.createElement("div");
	this.container.style.border = "1px solid #000";
	this.div = document.createElement("div");
	this.div.title = array_lang['851'];
	this.div.className = 'gbutton';
	this.container.appendChild(this.div);
	this.div.appendChild(document.createTextNode(array_lang['851'])); // 면적

	GEvent.addDomListener(this.div, "click", function() {
		if(this.style.fontWeight == 'bold') {
			me.clear();
		}
		else {
			if(distance_control) distance_control.clear();
			if(direction_control) direction_control.clear();
			if(streetview_control) streetview_control.clear();
			if(weather_control) weather_control.clear();
			if(elevation_control) elevation_control.clear();

			this.style.fontWeight = 'bold';
			this.style.color = '#FF0000';
			this.innerHTML = array_lang['30'];

			var ll = map.getBounds().getNorthEast();
			me.label = new ELabel(ll,array_lang['143'],null,new GSize(15,8)); // 지도를 클릭하세요.
			map.addOverlay(me.label);

			me.map_mousemove_listener = GEvent.addListener(map, 'mousemove', function(latlng) { // http://esa.ilmari.googlepages.com/mymapsmarker.htm
				me.label.setLatLng(latlng);
			});
			me.poly = new GPolygon([],'#0000FF',2,0.7,'#0000FF',0.2);
			map.addOverlay(me.poly);

			me.poly.enableDrawing();
			me.poly.enableEditing({onEvent: 'mouseover'});
			me.poly.disableEditing({onEvent: 'mouseout'});

			GEvent.addListener(me.poly, 'click', function(ll, index) {
				if(typeof index == "number") this.deleteVertex(index);
			});
			GEvent.addListener(me.poly, 'endline', function(ll, index) {
				if(me.label) map.removeOverlay(me.label);
			});
			GEvent.bind(me.poly, "lineupdated", null, function() {
				var n = me.poly.getVertexCount();
				if(n >= 3) me.label.setContents(array_lang['144']); // 끝내려면 마지막 지점 클릭
				me.show();
			});
			me.label.setContents(array_lang['143']);
		}
	});
	map.getContainer().appendChild(this.container);
	return this.container;
}
AreaControl.prototype.getDefaultPosition = function() {
	var x = this.opt.x ? this.opt.x : 265;
	var y = this.opt.y ? this.opt.y : 7;
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(x,y));
}
AreaControl.prototype.show = function() {
	if(this.poly.label) map.removeOverlay(this.poly.label);
	var s = poly2area(this.poly);
	var latlng = this.poly.getBounds().getCenter();
	this.poly.label = new ELabel(latlng,s,{color:'#FFFFFF',fill_color:'#CC0000',line_color:'#930000'});
	map.addOverlay(this.poly.label);
}
AreaControl.prototype.clearListeners = function() {
	if(this.map_mousemove_listener) GEvent.removeListener(this.map_mousemove_listener);
}
AreaControl.prototype.clearMarkers = function() {
	if(this.label) map.removeOverlay(this.label);
	if(this.poly) {
		this.poly.disableEditing();
		map.removeOverlay(this.poly);
		if(this.poly.label) map.removeOverlay(this.poly.label);
	}
}
AreaControl.prototype.clear = function() {
	this.clearListeners();
	this.clearMarkers();
	this.div.style.fontWeight = 'normal';
	this.div.style.color = '#000000';
	this.div.innerHTML = array_lang['851'];
}

//---------------------
// 길 찾기 도구
//---------------------
function DirectionControl(opt) {
	this.opt = opt ? opt : {};
}
DirectionControl.prototype = new GControl();
DirectionControl.prototype.initialize = function(map) {
	var me = this;

	me.play_icon = new GIcon(G_DEFAULT_ICON);
	me.play_icon.image = 'http://www.google.com/intl/en_de/mapfiles/icon-dd-play-trans.png';
	me.play_icon.shadow = 'http://www.google.com/mapfiles/shadow50.png';
	me.play_icon.iconSize = new GSize(24, 38);
	me.play_icon.shadowSize = new GSize(37, 34);
	me.play_icon.iconAnchor = new GPoint(12, 40);
	me.play_icon.infoWindowAnchor = new GPoint(19, 2);
	me.play_icon.infoShadowAnchor = new GPoint(18, 25);

	me.stop_icon = new GIcon(me.play_icon);
	me.stop_icon.image = 'http://www.google.com/intl/en_de/mapfiles/icon-dd-stop-trans.png';

	this.container = document.createElement("div");
	this.container.style.border = "1px solid #000";
	this.div = document.createElement("div");
	this.div.title = array_lang['688'];
	this.div.className = 'gbutton';
	this.container.appendChild(this.div);
	this.div.appendChild(document.createTextNode(array_lang['688']));

	GEvent.addDomListener(this.div, "click", function() {
		if(this.style.fontWeight == 'bold') {
			me.clear();
		}
		else {
			if(distance_control) distance_control.clear();
			if(area_control) area_control.clear();
			if(streetview_control) streetview_control.clear();
			if(weather_control) weather_control.clear();
			if(elevation_control) elevation_control.clear();

			this.style.fontWeight = 'bold';
			this.style.color = '#FF0000';
			this.innerHTML = array_lang['30'];

			var ll = map.getBounds().getNorthEast();
			me.hover_marker = new GMarker(ll,{icon:me.play_icon});
			map.addOverlay(me.hover_marker);

			me.hover_marker.label = new ELabel(ll,array_lang['568'],null,new GSize(16,-16)); // 출발지를 클릭하세요.
			map.addOverlay(me.hover_marker.label);
			GEvent.addListener(me.hover_marker, 'remove', function() {
				map.removeOverlay(me.hover_marker.label);
			});

			me.map_mousemove_listener = GEvent.addListener(map, 'mousemove', function(latlng) { // http://esa.ilmari.googlepages.com/mymapsmarker.htm
				me.hover_marker.setLatLng(latlng);
				me.hover_marker.label.setLatLng(latlng);
			});
			me.map_click_listener = GEvent.addListener(map, 'click', function(overlay, latlng) {
				if(latlng) {
					if(me.play_marker) {
						me.stop_marker = new GMarker(latlng,{icon:me.stop_icon,draggable:true,bouncy:false,title:array_lang['36']});
						map.addOverlay(me.stop_marker);
						//GEvent.addListener(me.stop_marker, 'drag', function() {
						//	me.gdirs.loadFromWaypoints([me.play_marker.getLatLng(), me.stop_marker.getLatLng()],me.gdirs_opt);
						//});
						GEvent.addListener(me.stop_marker, 'dragend', function() {
							me.linkToGoogle();
						});
						me.clearListeners();
						map.removeOverlay(me.hover_marker);
						me.hover_marker = null;

						if(me.opt.link_to_google) {
							me.linkToGoogle();
						}
						else {
							me.gdirs.loadFromWaypoints([me.play_marker.getLatLng(), me.stop_marker.getLatLng()],me.gdirs_opt);
						}
					}
					else {
						me.play_marker = new GMarker(latlng,{icon:me.play_icon,draggable:true,bouncy:false,title:array_lang['36']});
						map.addOverlay(me.play_marker);
						//GEvent.addListener(me.play_marker, 'drag', function() {
						//	me.gdirs.loadFromWaypoints([me.play_marker.getLatLng(), me.stop_marker.getLatLng()],me.gdirs_opt);
						//});
						GEvent.addListener(me.play_marker, 'dragend', function() {
							me.linkToGoogle();
						});
						me.hover_marker.setImage('http://www.google.com/intl/en_de/mapfiles/icon-dd-stop-trans.png');
						me.hover_marker.label.setContents(array_lang['569']); // 도착지를 클릭하세요.
					}
				}
				else {
					me.clear();
				}
			});
		}
	});
	if(!me.opt.link_to_google) {
		var canvas = this.opt.canvas_id ? document.getElementById(this.opt.canvas_id) : null;
		me.gdirs = new GDirections(map,canvas);
		me.gdirs_opt = {preserveViewport:true,locale:lang};
		GEvent.addListener(me.gdirs, "load", function() {
			me.clearMarkers();
		});
		GEvent.addListener(me.gdirs, "error", function() {
			alert(array_lang['708']); // 길 찾기 정보가 없습니다.
			me.clear();
		});
	}
	map.getContainer().appendChild(this.container);
	return this.container;
}
DirectionControl.prototype.getDefaultPosition = function() {
	var x = this.opt.x ? this.opt.x : 265;
	var y = this.opt.y ? this.opt.y : 7;
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(x,y));
}
DirectionControl.prototype.linkToGoogle = function() {
	var saddr = this.play_marker.getLatLng().toUrlValue();
	var daddr = this.stop_marker.getLatLng().toUrlValue();
	window.open('http://www.google.com/maps?saddr=%40'+saddr+'&daddr=%40'+daddr+'&hl='+lang);
	//me.clear();
}
DirectionControl.prototype.clearListeners = function() {
	if(this.map_mousemove_listener) GEvent.removeListener(this.map_mousemove_listener);
	if(this.map_click_listener) GEvent.removeListener(this.map_click_listener);
}
DirectionControl.prototype.clearMarkers = function() {
	if(this.hover_marker != null) {
		map.removeOverlay(this.hover_marker);
		this.hover_marker = null;
	}
	if(this.play_marker != null) {
		map.removeOverlay(this.play_marker);
		this.play_marker = null;
	}
	if(this.stop_marker != null) {
		map.removeOverlay(this.stop_marker);
		this.stop_marker = null;
	}
}
DirectionControl.prototype.clear = function() {
	this.clearListeners();
	this.clearMarkers();
	if(this.gdirs) this.gdirs.clear();
	this.div.style.fontWeight = 'normal';
	this.div.style.color = '#000000';
	this.div.innerHTML = array_lang['688'];
}

//-------------------
// 스트리트 뷰 도구
//-------------------
function StreetViewControl(opt) {
	this.opt = opt ? opt : {};
}
StreetViewControl.prototype = new GControl();
StreetViewControl.prototype.initialize = function(map) {
	var me = this;
	me.map = map;
	me.guy = null;
	me.pano = null;
	me.client = new GStreetviewClient();
	me.streetviewoverlay = null;

	me.help = icon_help+'<b>'+array_lang['492']+'</b><br />'+array_lang['611']
		+'<div class="mt10"><a href="javascript:void(0)" onclick="map.zoomIn()" class="blue u">'+array_lang['438']+'</a> &nbsp; '
		+'<a href="javascript:void(0)" onclick="map.zoomOut()" class="blue u">'+array_lang['439']+'</a> &nbsp; '
		+'<a href="javascript:void(0)" onclick="tools_control_clear()" class="blue u">'+array_lang['30']+'</a>'
		+'</div>';

	this.container = document.createElement("div");
	this.container.style.border = "1px solid #000";
	this.div = document.createElement("div");
	this.div.title = array_lang['605'];
	this.div.className = 'gbutton';
	this.div.style.width = '70px';
	this.container.appendChild(this.div);
	this.div.appendChild(document.createTextNode(array_lang['496'])); // 스트리트 뷰

	var icon = new GIcon();
	icon.image = "http://maps.gstatic.com/mapfiles/cb/man_arrow-0.png";
	icon.transparent = "http://maps.gstatic.com/mapfiles/cb/man-pick.png";
	icon.imageMap = [26,13, 30,14, 32,28, 27,28, 28,36, 18,35, 18,27, 16,26,16,20, 16,14, 19,13, 22,8];
	icon.iconSize = new GSize(49, 52);
	icon.iconAnchor = new GPoint(25, 35);
	icon.infoWindowAnchor = new GPoint(25, 5);

	me.pano_canvas = document.createElement('div');
	me.pano_canvas.id = 'streetviewcontrol_infowin_pano';
	me.pano_canvas.style.display = 'none';
	me.pano_canvas.style.width = '640px';
	me.pano_canvas.style.height = '320px';
	document.body.appendChild(me.pano_canvas);

	GEvent.addDomListener(this.div, "click", function() {
		if(this.style.fontWeight == 'bold') {
			me.pano_canvas.style.display = 'none';
			me.clear();
		}
		else {
			if(distance_control) distance_control.clear();
			if(area_control) area_control.clear();
			if(direction_control) direction_control.clear();
			if(elevation_control) elevation_control.clear();

			this.style.fontWeight = 'bold';
			this.style.color = '#FF0000';
			this.innerHTML = array_lang['30']; // 취소

			me.streetviewoverlay = new GStreetviewOverlay();
			me.map.addOverlay(me.streetviewoverlay);

			me.guy = new GMarker(me.map.getCenter(), {icon:icon, draggable:true});
			me.map.addOverlay(me.guy);

			GEvent.addListener(me.guy, "remove", function() {
				if(me.streetviewoverlay) me.map.removeOverlay(me.streetviewoverlay);
			});
			GEvent.addListener(me.guy, "infowindowbeforeclose", function() {
				if(me.pano) me.pano.remove();
			});
			GEvent.addListener(me.guy, "dragend", function() {
				me.pano_canvas.style.display = 'block';
				me.client.getNearestPanorama(me.guy.getLatLng(), function(panoData) {
					if(panoData.code == 200) {
						var latlng = panoData.location.latlng;
						me.guy.setLatLng(latlng);
						//me.guy.openInfoWindowHtml('<iframe src="'+get_gsv_url(latlng.lat(),latlng.lng())+'" width="520" height="300" frameborder="0"></iframe>');

						me.guy.openInfoWindowHtml(me.pano_canvas);
						me.pano = new GStreetviewPanorama(me.pano_canvas,{latlng:latlng});
						GEvent.addListener(me.pano, "yawchanged", function(yaw) {
							var GUY_NUM_ICONS = 16;
							var GUY_ANGULAR_RES = 360 / GUY_NUM_ICONS;
							if(yaw < 0) yaw += 360;
							var guyImageNum = Math.round(yaw / GUY_ANGULAR_RES) % GUY_NUM_ICONS;
							var img = "http://maps.gstatic.com/mapfiles/cb/man_arrow-"+guyImageNum+".png";
							me.guy.setImage(img);
						});
						GEvent.addListener(me.pano, "initialized", function(svl) {
							if(svl && svl.latlng) me.guy.setLatLng(svl.latlng);
						});
					}
					else {
						me.pano_canvas.style.display = 'none';
						me.guy.openInfoWindowHtml(me.help); // Drag me to blue area. No blue area, No street view.
					}
				});
			});
			me.guy.openInfoWindowHtml(me.help); // Drag me to blue area. No blue area, No street view.
		}
	});
	map.getContainer().appendChild(this.container);
	return this.container;
}
StreetViewControl.prototype.getDefaultPosition = function() {
	var x = this.opt.x ? this.opt.x : 265;
	var y = this.opt.y ? this.opt.y : 7;
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(x,y));
}
StreetViewControl.prototype.clearListeners = function() {
	//if(this.map_mousemove_listener) GEvent.removeListener(this.map_mousemove_listener);
	//if(this.map_click_listener) GEvent.removeListener(this.map_click_listener);
}
StreetViewControl.prototype.clearMarkers = function() {
	if(this.guy != null) {
		map.removeOverlay(this.guy);
		this.guy = null;
	}
}
StreetViewControl.prototype.clear = function() {
	this.clearListeners();
	this.clearMarkers();
	this.div.style.fontWeight = 'normal';
	this.div.style.color = '#000000';
	this.div.innerHTML = array_lang['496'];
}

//---------------------
// 날씨 보기 도구
//---------------------
function WeatherControl(opt) {
	this.opt = opt ? opt : {};
}
WeatherControl.prototype = new GControl();
WeatherControl.prototype.initialize = function(map) {
	var me = this;
	this.container = document.createElement("div");
	this.container.style.border = "1px solid #000";
	this.div = document.createElement("div");
	this.div.title = array_lang['605'];
	this.div.className = 'gbutton';
	this.container.appendChild(this.div);
	this.div.appendChild(document.createTextNode(array_lang['605'])); // 날씨

	GEvent.addDomListener(this.div, "click", function() {
		if(this.style.fontWeight == 'bold') {
			me.clear();
		}
		else {
			if(distance_control) distance_control.clear();
			if(area_control) area_control.clear();
			if(direction_control) direction_control.clear();
			if(streetview_control) streetview_control.clear();
			if(elevation_control) elevation_control.clear();

			this.style.fontWeight = 'bold';
			this.style.color = '#FF0000';
			this.innerHTML = array_lang['30']; // 취소

			var ll = map.getBounds().getNorthEast();
			me.hover_marker = new GMarker(ll,{draggable:true,bouncy:false,title:array_lang['36']}); // 드래그해서 이동
			map.addOverlay(me.hover_marker);
			GEvent.addListener(me.hover_marker, 'dragend', function() {
				me.show_weather();
			});
			me.hover_marker.label = new ELabel(ll,array_lang['143'],null,new GSize(20,-8)); // 지도를 클릭하세요.
			map.addOverlay(me.hover_marker.label);
			GEvent.addListener(me.hover_marker, 'remove', function() {
				map.removeOverlay(me.hover_marker.label);
			});
			me.map_mousemove_listener = GEvent.addListener(map, 'mousemove', function(latlng) { // http://esa.ilmari.googlepages.com/mymapsmarker.htm
				me.hover_marker.setLatLng(latlng);
				me.hover_marker.label.setLatLng(latlng);
			});
			me.map_click_listener = GEvent.addListener(map, 'click', function(overlay, latlng) {
				if(latlng) {
					if(me.map_mousemove_listener) GEvent.removeListener(me.map_mousemove_listener);
					if(me.hover_marker.label) map.removeOverlay(me.hover_marker.label);
					me.hover_marker.setLatLng(latlng);
					me.show_weather();
				}
				else {
					me.clear();
				}
			});
		}
	});
	map.getContainer().appendChild(this.container);
	return this.container;
}
WeatherControl.prototype.getDefaultPosition = function() {
	var x = this.opt.x ? this.opt.x : 265;
	var y = this.opt.y ? this.opt.y : 7;
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(x,y));
}
WeatherControl.prototype.show_weather = function() {
	var me = this;
	var latlng = me.hover_marker.getLatLng().toUrlValue();
	me.hover_marker.openInfoWindowHtml('<img src="/img/spinner.gif" class="iconb" alt="" />');
	$.getJSON('/api/weather.php?lang='+lang+'&latlng='+latlng, function(json) {
		var s = parse_weather(json,true);
		if(s == '') s = array_lang['841'];
		me.hover_marker.openInfoWindowHtml(s);
	});
}
WeatherControl.prototype.clearListeners = function() {
	if(this.map_mousemove_listener) GEvent.removeListener(this.map_mousemove_listener);
	if(this.map_click_listener) GEvent.removeListener(this.map_click_listener);
}
WeatherControl.prototype.clearMarkers = function() {
	if(this.hover_marker != null) {
		map.removeOverlay(this.hover_marker);
		this.hover_marker = null;
	}
}
WeatherControl.prototype.clear = function() {
	this.clearListeners();
	this.clearMarkers();
	this.div.style.fontWeight = 'normal';
	this.div.style.color = '#000000';
	this.div.innerHTML = array_lang['605'];
}

//---------------------
// 해발 측정 도구
//---------------------
function ElevationControl(opt) {
	this.opt = opt ? opt : {};
}
ElevationControl.prototype = new GControl();
ElevationControl.prototype.initialize = function(map) {
	var me = this;
	this.container = document.createElement("div");
	this.container.style.border = "1px solid #000";
	this.div = document.createElement("div");
	this.div.title = array_lang['845'];
	this.div.className = 'gbutton';
	this.container.appendChild(this.div);
	this.div.appendChild(document.createTextNode(array_lang['845'])); // 해발

	GEvent.addDomListener(this.div, "click", function() {
		if(this.style.fontWeight == 'bold') {
			me.clear();
		}
		else {
			if(distance_control) distance_control.clear();
			if(area_control) area_control.clear();
			if(direction_control) direction_control.clear();
			if(streetview_control) streetview_control.clear();
			if(weather_control) weather_control.clear();

			this.style.fontWeight = 'bold';
			this.style.color = '#FF0000';
			this.innerHTML = array_lang['30']; // 취소

			var ll = map.getBounds().getNorthEast();
			me.hover_marker = new GMarker(ll,{draggable:true,bouncy:false,title:array_lang['36']}); // 드래그해서 이동
			map.addOverlay(me.hover_marker);
			GEvent.addListener(me.hover_marker, 'dragend', function() {
				me.show_Elevation();
			});
			me.hover_marker.label = new ELabel(ll,array_lang['143'],null,new GSize(20,-8)); // 지도를 클릭하세요.
			map.addOverlay(me.hover_marker.label);
			GEvent.addListener(me.hover_marker, 'remove', function() {
				map.removeOverlay(me.hover_marker.label);
			});
			me.map_mousemove_listener = GEvent.addListener(map, 'mousemove', function(latlng) { // http://esa.ilmari.googlepages.com/mymapsmarker.htm
				me.hover_marker.setLatLng(latlng);
				me.hover_marker.label.setLatLng(latlng);
			});
			me.map_click_listener = GEvent.addListener(map, 'click', function(overlay, latlng) {
				if(latlng) {
					if(me.map_mousemove_listener) GEvent.removeListener(me.map_mousemove_listener);
					if(me.hover_marker.label) map.removeOverlay(me.hover_marker.label);
					me.hover_marker.setLatLng(latlng);
					me.show_elevation();
				}
				else {
					me.clear();
				}
			});
		}
	});
	map.getContainer().appendChild(this.container);
	return this.container;
}
ElevationControl.prototype.getDefaultPosition = function() {
	var x = this.opt.x ? this.opt.x : 265;
	var y = this.opt.y ? this.opt.y : 7;
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(x,y));
}
ElevationControl.prototype.show_elevation = function() {
	var me = this;
	var latlng = me.hover_marker.getLatLng();
	me.hover_marker.openInfoWindowHtml('<img src="/img/spinner.gif" class="iconb" alt="" />');
	$.post('/api/elevation.php',{lang:lang,lat:latlng.lat(),lng:latlng.lng()}, function(r) {
		var s = '';
		if(r == '') {
			s = 'No information';
		}
		else {
			var a = r.split(' = ');
			s+= '<div>'+array_lang['847']+': '+latlng.lat()+'</div>';
			s+= '<div>'+array_lang['848']+': '+latlng.lng()+'</div>';
			s+= array_lang['845']+': <span class="title blue">'+a[0]+'</span> (<span class="green">'+a[1]+'</span>)';
		}
		if(me.hover_marker) me.hover_marker.openInfoWindowHtml('<div class="lh20 b">'+s+'</div>');
	});
}
ElevationControl.prototype.clearListeners = function() {
	if(this.map_mousemove_listener) GEvent.removeListener(this.map_mousemove_listener);
	if(this.map_click_listener) GEvent.removeListener(this.map_click_listener);
}
ElevationControl.prototype.clearMarkers = function() {
	if(this.hover_marker != null) {
		map.removeOverlay(this.hover_marker);
		this.hover_marker = null;
	}
}
ElevationControl.prototype.clear = function() {
	this.clearListeners();
	this.clearMarkers();
	this.div.style.fontWeight = 'normal';
	this.div.style.color = '#000000';
	this.div.innerHTML = array_lang['845']; // 해발
}