function DiscoverMap(){
	if (GBrowserIsCompatible()) {
		G_HYBRID_MAP.getName=function($short){
			if($short){
				return 'Sat';
			} else {
				return 'Satellite';
			}
		};
		G_PHYSICAL_MAP.getName=function($short){
			if($short){
				return 'Phy';
			} else {
				return 'Physical';
			}
		};
		G_NORMAL_MAP.getName=function($short){
			if($short){
				return 'Nor';
			} else {
				return 'Normal';
			}
		};
		//	var _mLastResult = "Reset map position and zoom level"; 
		this.map=new GMap2(document.getElementById('map'), {mapTypes:[G_NORMAL_MAP, G_SATELLITE_MAP, G_HYBRID_MAP, G_PHYSICAL_MAP ]});
		this.map.setCenter(new GLatLng(0, 0), 0, G_NORMAL_MAP);
		
		this.map.addControl(new GHierarchicalMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7)));
		this.map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7)));
		
		this.clusterer=new ClusterMarker(this.map);
		var $map=this.map, $clusterer=this.clusterer;	//	req'd for function closure
		
		GEvent.addListener($clusterer, 'refreshed', function($status){
			for (var i=$status.length-1; i>=0; i--){
				if($map._activeMarkerIndex===i){ $status[i]+=' active'; }
				document.getElementById('anchor'+i).className=$status[i];
			}
		});
		
		GEvent.addListener($clusterer, 'clustermouseover', function($markers) {
			var i, $id;
			for(i=$markers.length-1; i>=0; i--){
				$id='anchor'+$markers[i].index;
				document.getElementById($id).style.backgroundColor='#00FF00';	//	use multiple classes instead of individual properties
			}
		});
		GEvent.addListener($clusterer, 'clustermouseout', function($markers) {
			var i, $id;
			for(i=$markers.length-1; i>=0; i--){
				$id='anchor'+$markers[i].index;
				document.getElementById($id).style.backgroundColor='';
			}
		});
		
		GEvent.addListener(this.map, 'infowindowopen', function(){
			var $li=document.getElementById('anchor'+$map._activeMarkerIndex);
			$li.className=$li.className+' active';
		});
		
		GEvent.addListener(this.map, 'infowindowclose', function(){
			var $li=document.getElementById('anchor'+$map._activeMarkerIndex);
			$class=$li.className;
			$class=$class.replace(/\sactive/,'');
			$li.className=$class;
			$map._activeMarkerIndex=false;
		});
		
		GEvent.addListener(this.map, 'moveend', function() { $map._lastCenter=$map.getCenter(); });
		GEvent.addListener(this.map, 'resize', function() { $map.setCenter($map._lastCenter); });
	}
}

DiscoverMap.prototype.getMarkers=function(){
	function createMarker($args) {
		var $marker=new GMarker($args.location, {title:$args.name, icon:$icon, draggable:true});
		//	var $marker=new GMarker($args.location, {title:$args.name, icon:$icon});
		var $html='<div class="infowindow">'+$args.html+'</div>';
		$marker.index=$args.index;
		GEvent.addListener($marker, 'click', function(){
			if($map._activeMarkerIndex!==$marker.index){
				$map.openInfoWindowHtml($marker.getLatLng(), $html, {maxWidth:388});
				$map._activeMarkerIndex=$marker.index;
			} else {
				$map.closeInfoWindow();
			}
		});
		GEvent.addListener($marker, 'dragend', function() { document.getElementById('title').innerHTML=$marker.getLatLng(); });
		return $marker;
	}
	var $icon=new GIcon(), $this=this, $map=this.map;
	$icon.image='images/marker_icons/mm_20_red.png';
	$icon.iconSize=new GSize(12, 20);
	$icon.iconAnchor=new GPoint(6, 17);
	GDownloadUrl('scripts/query.js', function($file, $code) {
		if ($code===200) {
			var $json=[];
			eval($file);
			var i, j=$json.length, $row, $markers=[], $linksHtml='<ul>';
			for (i=0; i<j; i++) {
				$row=$json[i];
				$row.index=i;
				$markers.push(createMarker($row));
				$linksHtml+='<li id="anchor'+i+'" onclick="map.menuSelect('+i+')">'+$row.name+'</li>';
			}
			$linksHtml+='</ul>';
			document.getElementById('menu').innerHTML=$linksHtml;
			$this.clusterer.addMarkers($markers);
			$this.clusterer.fitMapToMarkers();
			$this.map.savePosition();
		} else {
			GLog.write('DB query failed, error code: '+$code);
		}
	});
};

DiscoverMap.prototype.menuSelect=function($id){
	if(this.map._activeMarkerIndex!==$id){
		this.clusterer.triggerClick($id);
	} else {
		this.map.closeInfoWindow();
	}
};
