var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

    function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
				map.setCenter(new GLatLng(-23.598923, -46.637607), 16);
				map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());



        var baseIcon = new GIcon();
        baseIcon.shadow = "logo.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);

        // Creates a marker whose info window displays the letter corresponding
        // to the given index.
    function createMarker(point, index) {
          // Create a lettered icon for this point using our icon class
         // var letter = String.fromCharCode("A".charCodeAt(0) + index);
          var letteredIcon = new GIcon(baseIcon);
          letteredIcon.image = "logo.png";
				letteredIcon.iconSize = new GSize(40, 35);
          // Set up our GMarkerOptions object
          markerOptions = { icon:letteredIcon };
          var marker = new GMarker(point, markerOptions);

          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml("<p style=\"text-align:center;\"><img src=\"logo2.png\" /></p><p style=\"text-align:center;\">Rua Ten. Gomes Ribeiro, 182 S&atilde;o Paulo - SP, 04038-040</p>");
          });
          return marker;
        }

        // Add 10 markers to the map at random locations
        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngSpan = northEast.lng() - southWest.lng();
        var latSpan = northEast.lat() - southWest.lat();
        for (var i = 0; i < 1; i++) {
           //var latlng = new GLatLng(southWest.lat() + latSpan * Math.random(),
           // southWest.lng() + lngSpan * Math.random());
					var latlng = new GLatLng(-23.598923, -46.637607);
          map.addOverlay(createMarker(latlng, i));  
	
					//cria o marker ou ponto do mapa
					/*latlng = new GLatLng(-23.594587, -46.6372983);
				          map.addOverlay(createMarker(latlng, 1));*/

        }


        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        //GEvent.addListener(gdir, "error", handleErrors);

        setDirections("", "R. Tenente Gomes Ribeiro, 182 - 04038-040 - Sao Paulo", "pt_BR");
      }
    }
    
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

  function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Nao corresponde a uma localizacao geografica por favor digite: \n Ex: SP, Sao Paulo, Av Paulista 900\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("Digite o endereco de origem para calcular o seu Destino ate a Cielo. \n Ex: SP, Sao Paulo Av Paulista, 900");
	   
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
	window.onload=function()
	{
		initialize();
	}
	window.onunload=function()
	{
		GUnload();
	}