var tto; var allLoadedPolygons = new Array();
function load(zoneId){
	if (!GBrowserIsCompatible()) {
		alert('Sorry, your browser is not compatible');
	}else{
		//Load Dependencies
		loader.loadScriptRegistry('js/scriptRegistry.js');
		loader.require('Google.PolygonLoader');
		loader.require('js/wtfPolyLoaderFunctions.js');
		loader.require('Google.ToolTipOverlay');
		//var point = new GLatLng(lat,lon);
		var map = new GMap2(document.getElementById("gmap"), {draggableCursor: 'pointer'});
		map.addOverlay(new GScreenOverlay('/images/wtf/shadowedgeleft.png', new GScreenPoint(0,0,'pixels','pixels'), new GScreenPoint(0,0,'pixels','pixels'), new GScreenSize(10,720,'pixels','pixels')));
		map.addOverlay(new GScreenOverlay('/images/wtf/shadowedgetop.png', new GScreenPoint(0,1,'fraction','fraction'), new GScreenPoint(0,10,'pixels','pixels'), new GScreenSize(720,10,'pixels','pixels')));
		map.addMapType(G_PHYSICAL_MAP);
		map.addControl(new GSmallMapControl());
		map.enableContinuousZoom();
		map.enableScrollWheelZoom();
		map.removeMapType(G_NORMAL_MAP);
		// Set up the ToolTipOverlay object
		tto = new ToolTipOverlay();
		map.addOverlay(tto);
//	map.setCenter(point, gmscale,G_PHYSICAL_MAP);
		 // Create the GPolygon object and add it to the map
		/*
		* The loadStyledPolygon function takes 4 parameters:
		* 1: The ID code of the polygon to be loaded
		* 2: A callback function that will be exectued when the polygon geometry is retrieved
		* 3: A property list (object literal) of stroke style settings for the polygon
		* 4: A property list (object literal) of fill style settings for the polygon
		*
		* This function and the polyLoader object come from the GooglePolyTools.js script included above.
		*/
		polyLoader.loadStyledPolygon(
			zoneId, // the ID of the zone to load. So far only public zones are automatically supported.
			function(theLoadedPolygon){ // the callback function
			/*
			* This function is called when the requested polygon is loaded,
			* and is passed one parameter, which is the newly created GPolygon
			* object (passed in as "theLoadedPolygon").
			*/
			map.setCenter(
				new GLatLng(
					theLoadedPolygon.metadata.centroid.lat,
					theLoadedPolygon.metadata.centroid.lng
				),
				map.getBoundsZoomLevel(
					new GLatLngBounds(
						new GLatLng(
							theLoadedPolygon.metadata.bounds.s,
							theLoadedPolygon.metadata.bounds.w
						),
						new GLatLng(
							theLoadedPolygon.metadata.bounds.n,
							theLoadedPolygon.metadata.bounds.e
						)
					)
				),G_PHYSICAL_MAP
			);

			allLoadedPolygons.push(theLoadedPolygon);
			map.addOverlay(theLoadedPolygon);

			// Attach a simple pre-built ToolTip to the polygon.
			tto.attach(theLoadedPolygon, '<b>Zone:</b> <i>' + theLoadedPolygon.metadata.name + '</i>');

			// Add some event handlers to the polygon
			//GEvent.addListener(theLoadedPolygon, "mouseover", function(){
			//	document.getElementById('demoTextBoxId').value = "Mouse is over the polygon!";
			//});

			//GEvent.addListener(theLoadedPolygon, "mouseout", function(){
			//        document.getElementById('demoTextBoxId').value = "Mouse is not over anything.";
			//});

			//GEvent.addListener(theLoadedPolygon, "click", function(clickLocation){
			//       // note that within this function, "this" refers to the clicked polygon -- the target of the event.
			//        map.openInfoWindowHtml(clickLocation, 'You clicked on: ' + this.metadata.name);
			//});
			GEvent.addListener(theLoadedPolygon, "click", function(point){
				if (point){
					var list='?lat='+point.y+'&lon='+point.x+'&site='+gmsite+'&smap=1'+'&marine='+gmmarine+'&unit='+gmsi+'&lg='+gmlng;
					parent.location.href='MapClick.php'+list;
				}
			});//end addListener function
		},
		{ // the stroke settings
			color: "#ff0000",
			opacity: 0.6,
			weight: 2
		},
		{ // the fill settings
			fill: true,
			color: "#ff0000",
			opacity: 0.3,
                        outline: true
		}
		);



		GEvent.addListener(map, "click", function(overlay,point){
			if (point){
				var list='?lat='+point.y+'&lon='+point.x+'&site='+gmsite+'&smap=1'+'&marine='+gmmarine+'&unit='+gmsi+'&lg='+gmlng;
				parent.location.href='MapClick.php'+list;
			}
		});//end addListener function
		// put polygon on map (from gTopoMap.js)
//		if(points){
//			var polygon = new GPolygon(points, "#f33f00",1,1,"#ff0000");
//			map.addOverlay(polygon);
//		}
	//	var crosshair = new GIcon();
	//	crosshair.image = '/images/wtf/crosshair.png';
	//	crosshair.iconAnchor = new GPoint(8,8);
	//	map.addOverlay(new GMarker(new GLatLng(lat,lon), {
	//		icon: crosshair,
	//		clickable: false,
	//		title: 'Requested location'
	//	}));
	}
}


