//<![CDATA[

var map = null;
var geocoder = null;
var icon;
var collocat = true;

function initialize() {
	icon = new GIcon();
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.enableDoubleClickZoom();
		map.enableContinuousZoom();
		
		// icona d'El Punt Habitatge
		icon.image = "../../img/casa1.png";
		icon.shadow = "../../img/casa1-ombra.png";
		icon.iconSize = new GSize(40, 40);
		icon.shadowSize = new GSize(40, 40);
		icon.iconAnchor = new GPoint(20, 20);
		icon.infoWindowAnchor = new GPoint(30, 10);

		var missatge = new Array();
		var missatgeTmp = "";
		var fila = 0;
		var actuar = 1;

		var posaAdrecas = setInterval( function(){
		 	if (fila >= adreca.length) clearInterval(posaAdrecas);
			missatgeTmp = adreca[fila][1];
			geocoder = new GClientGeocoder();
 			geocoder.getLatLng(
				adreca[fila][0], 
				function(point) {
					if (fila == 1) {     
				   	map.setCenter(point, ampliacio);
			   	}
			   	var marker = new GMarker(point, icon);     
			   	map.addOverlay(marker);
			    // marker.openInfoWindowHtml(missatge1);
					
					var hh = new Array();
					var gg = marker.getPoint();
					gg = gg.toString();
					gg = gg.replace("(", "");
					gg = gg.replace(")", "");
					gg = gg.replace(".", "");
					hh = gg.split(",");
					missatge[Number(hh[0])] = missatgeTmp;
				  
			    GEvent.addListener(marker, "click", function() {
			    		marker.openInfoWindowHtml(missatge[Number(hh[0])]);
			    	}
			  	);
				}
			);
			fila++;
		}, 1000);
		

		//window.setTimeout( function() { map.panDirection(0.4, -0.8); }, 1000 );

		
	}
}


function showAddress(address) {
  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          alert(address + " not found");
        } else {
          map.setCenter(point, 13);
          var marker = new GMarker(point);
          map.addOverlay(marker);
          marker.openInfoWindowHtml(address);
        }
      }
    );
  }
}

//]]>
