﻿//<![CDATA[



	var map;

	var gLocalSearch;

	var geocoder;

	var pointTitle;
	var pointAdress;

	var chosen = [];



	// Create an object of GLayers

	var layers = {

	 pano: new GLayer("com.panoramio.all"),

	 wiki: new GLayer("org.wikipedia.en")

	};

	

	function loadMAP() {

		if (GBrowserIsCompatible()) {



		map = new GMap2(document.getElementById("map"));

		map.enableScrollWheelZoom();

		map.addControl(new GLargeMapControl());

		//map.addControl(new GMenuMapTypeControl());

		map.addControl(new GMapTypeControl());

		map.setCenter(new GLatLng(-(21.378917 + 0.01005), -(42.694845 + 0.000752)), 15);

		//-21.378917,-42.694845&amp;spn=0.03005,0.038452



		// bind a search control to the map, suppress result list

		gLocalSearch = new google.maps.LocalSearch(

			{

			   resultList : document.getElementById("results")

			});

		map.addControl(gLocalSearch, new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(2,-30)));

		geocoder = new GClientGeocoder();



		//map.addControl(new MoreControl());

		//map.addControl(new BoxControl());

		

		//map.addOverlay(layers['pano']); //Camada de fotos





		// Create a base icon for all of our markers that specifies the

	        // shadow, icon dimensions, etc.

	        /*baseIcon = new GIcon(G_DEFAULT_ICON);

	        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.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);*/

	

	        // 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 gMarkerIcon = new GIcon(baseIcon);

	          gMarkerIcon.image = "imagens/gMarker.png";

		  

	          // Set up our GMarkerOptions object

	          markerOptions = { icon:gMarkerIcon };

	          var marker = new GMarker(point, markerOptions);

	

	          GEvent.addListener(marker, "click", function() {

	            marker.openInfoWindowHtml("Marker <b>" + letter + "</b>");

	          });

	          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 < 10; i++) {

	          var latlng = new GLatLng(southWest.lat() + latSpan * Math.random(),

	            southWest.lng() + lngSpan * Math.random());

	          map.addOverlay(createMarker(latlng, i));

	        }*/

		//   updateCode();

		}

	}

	

	

   GSearch.setOnLoadCallback(loadMAP);



	function addIcon(icon) { // Add icon attributes



	 icon.shadow = "http://www.google.com/mapfiles/shadow50.png";

	 icon.iconSize = new GSize(19, 32);

	 icon.shadowSize = new GSize(37, 34);

	 icon.iconAnchor = new GPoint(9, 34);

	 icon.infoWindowAnchor = new GPoint(9, 2);

	 icon.infoShadowAnchor = new GPoint(18, 25);

	}





	function addClickevent(marker) { // Add a click listener to the markers

	

	 GEvent.addListener(marker, "click", function() {

	  marker.openInfoWindowHtml(marker.content);

	  /* Change count to continue from the last manually clicked marker

	  *  Better syntax since Javascript 1.6 - Unfortunately not implemented in IE.

	  *  count = gmarkers.indexOf(marker);

	  */

	  count = marker.nr;

	  stopClick = true;

	 });

	 

	 return marker;

	}





    // addAddressToMap() is called when the geocoder returns an

    // answer.  It adds a marker to the map with an open info window

    // showing the nicely formatted version of the address and the country code.

    function addAddressToMap(response) {

      map.clearOverlays();

      loadMAP();

      if (!response || response.Status.code != 200) {

        alert("Sorry, we were unable to geocode that address");

      } else {

        place = response.Placemark[0];

        point = new GLatLng(place.Point.coordinates[1],

                            place.Point.coordinates[0]);

        

        var icon = new GIcon();

       // icon.image = "http://www.festivalverefazerfilmes.com.br/2008/imagens/gMarker.png";
		icon.image = "http://www.festivalverefazerfilmes.com.br/2010/wp-content/themes/thematic/imagens/gMarker.png";

        addIcon(icon);

        

        markerOptions = { icon:icon };

        var marker = new GMarker(point, markerOptions);

        // var content = '<br>' + place.address + '<br>';

        // '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode;
		
		//if(!pointAdress) {
		//	pointAdress = place.address;
		//}

	var content = 	"\n<div id='infoWCustom'>" +

			"\n\t<h2 style='font-size: 16px'><a href='javascript:void(0)'>" + pointTitle + "</a></h2>" +

			"\n\t<p>" + pointAdress + "</p>" +

			"\n</div>";

	marker.content = content;

	marker = addClickevent(marker);

        map.addOverlay(marker);



        GEvent.trigger(marker,'click');

      }

    }



    // showLocation() is called when you click on the Search button

    // in the form.  It geocodes the address entered into the form

    // and adds a marker to the map at that location.

    function showLocation(point, title, adress) {

      pointTitle = title;
	  if(adress) {
	  	pointAdress = adress;
	  } else {
		pointAdress = "";
	  }
      geocoder.getLocations(point, addAddressToMap);

    }



//]]>


