var map = null;  
var geocoder = null;
var coordinates = null;
var address = '1801 Bush Street, Suite 121, San Francisco, CA 94109';
var display = "<form method='GET' action='http://maps.google.com/maps' target='_blank'>";
    display = display + "<div style=\"margin: 20px 0 0 0;\">";
    display = display + "<img style=\"float: left; padding: 0 0 20px 10px;\" src=\"./Images/CompassWhite.gif\">";
    display = display + "<h1 style=\"margin: 0;\">Chosen Futures</h1>";
    display = display + "<p style=\"line-height: normal;\">1801 Bush Street, Suite 121<br />San Francisco, CA 94109<br /><br />Phone: 415-346-6121<br />Mobile: 415-642-0225</p>";
    display = display + "</div>";
    
    
    display = display + "<h2 style=\"margin: 0 0 5px 0;\">Get directions to Chosen Futures from:</h2>";
    display = display + "<input type=\"text\" class=\"Textbox\" name=\"saddr\" size=\"30\">";
    display = display + "<input type=\"hidden\" name=\"daddr\" value=\"37.787725273188094, -122.42747783660888\">";
    display = display + "<input type=\"submit\" class=\"Button\" value=\"Go\" style=\"padding: 0 3px\">";
    display = display + "<input type=\"hidden\" name=\"hl\" value=\"en\">"
    display = display + "</form>";
var streetViewContainer = "<div id='divStreetView' style='width: 400px; height: 200px;'></div>";  

function Gload() 
{
    if (GBrowserIsCompatible()) 
    {
        map = new GMap2(document.getElementById("GoogleMap"));
        map.enableDoubleClickZoom();
        map.enableContinuousZoom();
        map.addControl(new GLargeMapControl());        
        map.addControl(new GMapTypeControl()); 
        
        geocoder = new GClientGeocoder();
        ShowInfo(address);
    }
}
function ShowInfo(address) 
{
	geocoder.getLatLng(address, function(point) 
	{       
		map.setCenter(point, 16);
		
        // Create our "tiny" marker icon
        var iconChosenFutures = new GIcon(G_DEFAULT_ICON);
        iconChosenFutures.image = "/Images/Compass.png";
        iconChosenFutures.printImage = "/Images/Compass.gif";
        iconChosenFutures.moxPrintImage = "/Images/Compass.gif";
        iconChosenFutures.iconSize = new GSize(60, 58);     
        iconChosenFutures.shadow = "";
        iconChosenFutures.iconAnchor = new GPoint(40, 55);
        iconChosenFutures.imageMap=[0,19, 50,1, 42,55];
    
        // Set up our GMarkerOptions object
        markerOptions = { icon:iconChosenFutures };
        
        //add ChosenFutures marker
        var markerChosenFutures = new GMarker(point, markerOptions)
        map.addOverlay(markerChosenFutures);  
		
		//Add click event to icon					
		GEvent.addListener(markerChosenFutures, "click", function() {
            markerChosenFutures.openInfoWindowTabs([new GInfoWindowTab('Details',display), new GInfoWindowTab('Street View',streetViewContainer)]);
            lat = point.lat();
            lng = point.lng();
            setTimeout("displayStreetView(lat, lng)", 1000);
        });
	}); 
}    

function ShowInforWindow()
{
     
}

function displayStreetView(lat, lng)
{
    var streetView = new GStreetviewPanorama(document.getElementById("divStreetView"));
    var streetViewPoint = new GLatLng(37.787725273188094, -122.42747783660888);
    streetViewPOV = {yaw:0,pitch:0,zoom:0};
    streetView.setLocationAndPOV(streetViewPoint, streetViewPOV);
    GEvent.addListener(streetView, "error", handleNoFlash);
}
  
function handleNoFlash(errorCode) 
{
    if (errorCode == 603) 
    {
        alert("Error: Flash doesn't appear to be supported by your browser");
        return;
    }
}  
