	var map;
	var iconMgr;
	
	var GX_isHybrid = false;
	
	var svc;
	var GX_systemState ="init";
	var defaultZoom = 17;
	var minZoom = 16;
	
	_mF[49] = "";
 	_mF[56] = 39;
 	_mF[57] = "http://cbk0.google.com";
 	_mF[59] = true;

	function GeosembleLogoControl(){
	}
	GeosembleLogoControl.prototype=new GControl();
	GeosembleLogoControl.prototype.initialize=function(map){
		var container=document.createElement("div");
		container.innerHTML='<a onclick="window.open(this.href); return false;" href="http://www.geosemble.com/">' +
			'<span style="width:90px;height:31px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/poweredByGeosemble.png\');"><img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="images/poweredByGeosemble.png" width="90" height="31" border="0" ALT="Powered by Geosemble" TITLE="Powered by Geosemble"></span>' +
			'</a>';
		map.getContainer().appendChild(container);
		return container;
	}
	GeosembleLogoControl.prototype.getDefaultPosition=function(){
		return new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize(68,5));
	}

	function initIconManager() {
		iconMgr = new MarkerManager(map);
	}
	
    function initialize(mapdiv, width, height,showHybrid, GX_lat, GX_lon, zoom) {
    	map = new GMap2(mapdiv, { size: new GSize(width,height) } );
    	map.removeMapType(G_NORMAL_MAP);
	
		
		map.removeMapType(G_SATELLITE_MAP);	
				
		GX_isHybrid = false;
		map.setCenter(new GLatLng(GX_lat, GX_lon), zoom);
		      	
      	map.addControl(new GLargeMapControl());
	 
	    var mapControl = new GMapTypeControl();
	    map.addControl(mapControl);
	    
		this.map.addControl(new GeosembleLogoControl());
	    
	    //Add the GX_street view client
	    svc = new GStreetviewClient();	    		
       
        //if(applicationMode == "admin") {
        //	GEvent.addListener(map, 'click', function(overlay, point) {
        //		if(point)  	alert(point.y + ", " + point.x);
		//	});       	
        //}
        
        
        
        GEvent.addListener(map, "infowindowbeforeclose", function() {
    		if(panorama != null) {    		
    			panorama.remove();
    			panormam = null;
    		}    		
    	});
    	
    	
    	initIconManager();    	     	
    	GX_interpretSearchParams();    
    }
		
	var GX_flashSupported = true;
	function handleNoFlash(errorCode) {
	  if (errorCode == 603) {
	    //alert("Error: Flash doesn't appear to be supported by your browser");
	    //return;
	    document.getElementById('pano').innerHTML = getFlashErrorMsg();
	    GX_flashSupported = false;
	  }
	} 
	
	function getFlashErrorMsg() {
		var msg = "<BR><BR><div style=\"border-style:solid;border-width:thin;padding-left:5px;padding-right:5px;padding-top:20px;padding-bottom:20px;\"><B>To use street view, you need Adobe Flash Player version 9 or newer.<BR>" +
					"<a class=\"onGoogle\" href=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" taget=\"_blank\">Get the latest Flash Player</a></B></div>";
		return msg;
	}
		
	function GX_showHybridMap() {	
	
	/*	if(!GX_isHybrid) {	        
	        map.addMapType(G_HYBRID_MAP);
	        map.setMapType(G_HYBRID_MAP);
	        map.removeMapType(G_SATELLITE_MAP);
	     }
	     GX_isHybrid = true; */
	}
	
	function GX_showSatelliteMap() {
	/*
		if(GX_isHybrid) {
			map.addMapType(G_SATELLITE_MAP);
			map.setMapType(G_SATELLITE_MAP);
			map.removeMapType(G_HYBRID_MAP);
		}
		GX_isHybrid = false;
	*/
	}
	
	function GX_setGMapCenter(lat, lon) {
        map.setCenter(new GLatLng(lat, lon));
        //GX_showSatelliteMap();
	}

	function GX_setZoom(z) {
        map.setZoom(z);
	}
	    
    function GX_createMarker(point, icon1, tooltip, zIndex) {
    	//var marker = new GMarker(point, {icon:icon1, zIndexProcess:importanceOrder});
    	//marker.importance = zIndex;
    	var marker = new GX_GSIcon(point, tooltip, icon1, imageWidth, imageHeight, zIndex); 
    	
    	
       	return marker;
    }
        
	function GX_createPolyLine(lineLatLonPoints, color, thickness) {
		var polyline = new GPolyline(lineLatLonPoints, color, thickness);	
		return polyline;
	}
	
	function GX_showLine(lineLatLonPoints, color, thickness, clickText) {
		var polyline = new GPolyline(lineLatLonPoints, color, thickness);
		//iconMgr.addMarker(polyline, minZoom);
		map.addOverlay(polyline);
		GEvent.addListener(polyline, "click", function(overlay,  latlng,  overlaylatlng) {				
					
			if(window.event) {
				document.getElementById('divTooltip').style.left = window.event.clientX + "px";
				document.getElementById('divTooltip').style.top = window.event.clientY + "px";
			} else {
				var offset=map.fromLatLngToContainerPixel(overlay);
				
				var x = offset.x + document.getElementById('map_canvas').offsetLeft;
				var y = offset.y + document.getElementById('map_canvas').offsetTop;
				
				document.getElementById('divTooltip').style.left = x + "px";
				document.getElementById('divTooltip').style.top = y + "px";
			}	
			document.getElementById('divTooltip').innerHTML = clickText;
			document.getElementById('divTooltip').style.display = "block";
			window.setTimeout(function() {
				document.getElementById('divTooltip').style.display = "none";
				}, 5000);
		});
		return polyline;
	}
	function GX_showPolyLine(polyline) {
		//iconMgr.addMarker(polyline, minZoom);
		map.addOverlay(polyline);
	}

	
	function GX_setCenter(slat, slon) {
			//alert(slat + "," + slon);
		document.getElementById('state').value = "init";
		GX_setGMapCenter(parseFloat(slat), parseFloat(slon));
		GX_systemState = "init";
	}

	function GX_isInfoWindowClosed() {
		//alert(map.getInfoWindow().isHidden());
		return map.getInfoWindow().isHidden();
	}
	
	function GX_isStreetViewAvailable(point, availFunc, notAvailFunc) {
		svc.getNearestPanorama(point, 
			function(reply) {
				var present = false;
				if (reply.code == 200) {
					if (reply.Location) {						
						present = true;						
					} 
				}
				if(present == true) {
					availFunc(reply);
				} else {
					notAvailFunc();
				}
			}
		);
	}
	
	function GX_showStreetView(text) {
		var marker = iconMgr.getCurrentOpenMarker();
		GX_isStreetViewAvailable(marker.getPoint(),
			function(reply) { //Street View is available
				var panNode = GX_getPanoramaNode(reply, marker.getPoint(), text);
				iconMgr.openInfoWindowHtml(marker, panNode);
			},
			function() { //SV not available
			}
		);
	}
	
	var panorama = null;
	var firstPanoramaAccess = true;
	function GX_getPanoramaNode(reply, point, panoramaText) {
		var divStreetView = document.getElementById('divStreetView');						
		if(divStreetView == null) {
			divStreetView = document.createElement('div');
			divStreetView.id = "divStreetView";
		} else {
			divStreetView.removeChild(document.getElementById('pano'));
			divStreetView.removeChild(document.getElementById('gazTextWithSV'));
		}
	
		var contentNode = document.createElement('div');  						
		contentNode.id = 'pano';  						
		if(GX_flashSupported == false) {
			contentNode.innerHTML = getFlashErrorMsg();
		} else {
			if(firstPanoramaAccess == true) {
				panorama = new GStreetviewPanorama(contentNode);
				GEvent.addListener(panorama, "error", handleNoFlash);
				panorama.setLocationAndPOV(point);		
			} else {
				contentNode.innerHTML = GX_getPanoramaHtml(reply);
			}
		}
		firstPanoramaAccess = false;
		var gazTextWithSV = document.createElement('div');
		gazTextWithSV.id = "gazTextWithSV";
		gazTextWithSV.innerHTML = panoramaText;
			
		divStreetView.appendChild(gazTextWithSV);
		divStreetView.appendChild(contentNode);
		return 	divStreetView;				
	}
		
	
	function GX_getPanoramaHtml(reply) {
		var html = "<div class=\"header\"><b>"+
				reply.Location.description+
				"</div></b>" + 
				"<div class=\"bubble\">" +
				"<embed src=\"http://maps.google.com/mapfiles/cb/googlepano.040.swf\"" +
					" quality=\"high\" bgcolor=\"#EFEFEF\" style=\"width: 250px; " +
					"height: 180px;\"" +
					" wmode=\"opaque\" swliveconnect=\"false\" id=\"googlepano\"" +
					" allowscriptaccess=\"always\" type=\"application/x-shockwave-flash\"" +
					" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" scale=\"noscale\"" +
					" salign=\"lt\" flashvars=\"panoId="+reply.Location.panoId+
					"&amp;directionMap=N:N,W:W,S:S,E:E,NW:NW,NE:NE,SW:SW,SE:SE&amp;yaw=350.08435065836153&amp;zoom=0&amp;browser=3&amp;serverURLPrefix=http://cbk0.google.com/cbk&amp;pitch=10.983050525042998&amp;viewHeight=0.616426117417295\"" +
					" align=\"middle\"></embed></div>";
		return html;	
	}
	
	
	function GX_showMarker(marker, markerText, showStreetView) {
 		var divId = "gazText";
		if(markerText.indexOf("name='multipleGazs'") == -1 && markerText.indexOf("<img") == -1)
			divId = "gazTextSingle";
		var txt = "<DIV id=\"" + divId + "\">" + markerText + "</DIV>";
					     	
     	if(showStreetView == true) {		
			GX_showStreetView(txt);	
		} else {			
		
			GX_isStreetViewAvailable(marker.getPoint(),
				function(reply) {	//Street View is available
					var svHtml = "<a class=\"onGoogle\" href=\"javascript:GX_showStreetView('" + markerText.quote() + "');\">Show Street View</a>" ;
					txt = "<DIV id=\"" + divId + "\">" + markerText + svHtml + "</DIV>";
					iconMgr.openInfoWindowHtml(marker, txt);
				},
				function() {	//Street View is not available				
					iconMgr.openInfoWindowHtml(marker, txt);				
				}
			);
		}
		        	
        GEvent.addListener(marker, "click", function() {			
			iconMgr.openInfoWindowHtml(marker, markerText);
		});		
	}	