// JavaScript Document

    //<![CDATA[
    var map = null;
    var geocoder = null;
	var div = null;




    function load(a, b, c, d, e) {
      if (GBrowserIsCompatible()) {
	    map = new GMap2(document.getElementById("map"));
		if (a == true) {map.enableScrollWheelZoom();}
		if (b == true) {map.addControl(new GScaleControl());}
		if (c == true) {map.addControl(new GOverviewMapControl());}
		if (d == true) {map.addControl(new GMapTypeControl());}
	        if (e == true) { map.addControl(new GLargeMapControl());}
		
        map.enableDoubleClickZoom();
        geocoder = new GClientGeocoder();
      }
    }

 function showAddress(address, contents, image) {
      if (geocoder) {
	
        geocoder.getLatLng(
          address,
          function(point) {

            if (!point) {
              //alert("No es troba la localització: " + address);
            } else {

			  map.setCenter(point, 17);
		      	var newIcon = new GIcon(G_DEFAULT_ICON);
    	      		 newIcon.image = image;
			  newIcon.iconSize = new GSize(20, 20);
			  newIcon.shadowSize = new GSize(20, 20);
			  newIcon.iconAnchor = new GPoint(9, 34);
			  newIcon.infoWindowAnchor = new GPoint(9, 2);
			  newIcon.infoShadowAnchor = new GPoint(18, 25);
			
			 var markerOptions = { maxWidth:400 };			  
			  
			  var marker = new GMarker(point, newIcon);
             		 map.addOverlay(marker);
		       //  marker.bindInfoWindowHtml(contents);

				

			//GEvent.addListener(marker, "click", function() {
        //    marker.openInfoWindowHtml(contents, markerOptions);
        //  });
	return marker;
            }
          }

        );

      }
    }

    function addAddressToMap(response) {
      map.clearOverlays();
      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]);
      	   
			  
		 marker = new GMarker(point);
        map.addOverlay(marker);
		         marker.openInfoWindowHtml(place.address);
				

			
      }
    }

function showLocation(address, contents, image) {
      geocoder.getLocations(address, addAddressToMap);
    }

 function showAddressCoord(address, contents, image) {
		
			  var point = new GLatLng(address);	
			  map.setCenter(point, 2);
		      	  var newIcon = new GIcon(G_DEFAULT_ICON);
    	      		  newIcon.image = image;
			  newIcon.iconSize = new GSize(27, 24);
			  newIcon.shadowSize = new GSize(27, 24);
			  newIcon.iconAnchor = new GPoint(9, 34);
			  newIcon.infoWindowAnchor = new GPoint(9, 2);
			  newIcon.infoShadowAnchor = new GPoint(18, 25);
			
			 var markerOptions = { maxWidth:400 };			  
			  
			  var marker = new GMarker(point, newIcon);
	
             		 map.addOverlay(marker);
		         marker.bindInfoWindowHtml(contents);

			GEvent.addListener(marker, "click", function() {
           		 marker.openInfoWindowHtml(contents, markerOptions);
         		 });

            }
       
    
function createSidebarEntry(marker, name, address) {
  var div = document.createElement('div');
  var html = name;
  div.innerHTML = html + '<br>';
  div.style.cursor = 'pointer';
  div.style.marginBottom = '5px';
  GEvent.addDomListener(div, 'click', function() {
    GEvent.trigger(marker, 'click');
  });
  GEvent.addDomListener(div, 'mouseover', function() {
    div.style.backgroundColor = '#eee';
  });
  GEvent.addDomListener(div, 'mouseout', function() {
    div.style.backgroundColor = '#fff';
  });
  return div;
}


    //]]>
