//<![CDATA[
/* A lot of the code is taken from other tutorials. */
function createMarker(point,html,icona,nomlloc) { /*------ Si es canvia lo de sota, també s'ha de canviar això!!! ------*/
	var marker = new GMarker(point,customIcons[icona]); /*------ S'agafen els valors de "icona" al fitxer XML per triar la icona!! ------*/
 	GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }, nomlloc);
        // save the info we need to use later for the side_bar
        gmarkers.push(marker);
        // add a line to the side_bar html
        side_bar_html += '<div class="side_bar-thumbnail-box"><div class="side_bar-thumbnail"><a href="javascript:myclick(' + (gmarkers.length-1) + ')">'+ nomlloc +'<\/a><\/div><\/div>';
	return marker;
   	}

      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
      }
/* ---------------------------------------------------------------------------------SI LA SIDEBAR NO FUNCIONA, MOSTRAR EL CODI DIRECTAMENT AMB HTML O PHP---------------------------------*/
/* ---------------------------------------------------------------------------------SI LA SIDEBAR NO FUNCIONA, MOSTRAR EL CODI DIRECTAMENT AMB HTML O PHP---------------------------------*/
	
function getMarks(url) { /* pass url during the call. */
	map.closeInfoWindow(); /*close any InfoWindows that happen to be open  */
	map.clearOverlays();
  	var request = GXmlHttp.create(); /* use the XML methods  */
    	request.open("GET", url, true);
    	request.onreadystatechange = function() {
     	if (request.readyState == 4) {	
		var xmlDoc = request.responseXML; /* php returns 'XML' */
		var markers = xmlDoc.documentElement.getElementsByTagName("marker"); 
		for (var loop1=0;loop1<markers.length;loop1++){
		var lat = parseFloat(markers[loop1].getAttribute("lat"));  /* data is string. */
			var lng = parseFloat(markers[loop1].getAttribute("lng")); 
			var point = new GLatLng(lat,lng);
			var county = markers[loop1].getAttribute("county");
			var type = markers[loop1].getAttribute("type");
			var icona = markers[loop1].getAttribute("icona");
			var nomlloc = markers[loop1].getAttribute("html");
			var html = "<b>" + markers[loop1].getAttribute("html") + "</b><br />" + markers[loop1].getAttribute("resum") + "<br /><br /><a href='veure.php?lloc=" + markers[loop1].getAttribute("id") + "'>Veure la fitxa i la galeria d'imatges</a>";
			var marker = createMarker(point,html,icona,nomlloc);
			map.addOverlay(marker);
			}
			        // put the assembled side_bar_html contents into the side_bar div
        document.getElementById("side_bar").innerHTML = side_bar_html;

		}
		};
	request.send(null);
}
	
//]]>