	var _actiu;

	var gmarkers = [];

	var side_bar_html = "";

 // A function to create the marker and set up the event window



  function createMarker(point,options, i) {      	

			var options2 = {title:options.title};

			var marker = new GMarker(point, options2);

			var html = pintaBocadillo(options);

      //var marker = new GMarker(point,options);

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

				marker.openInfoWindowHtml(html);

      });

      // save the info we need to use later for the side_bar

      gmarkers[i] = marker;

      // add a line to the side_bar html

      side_bar_html += '<a id="gog_' + i + '" href="javascript:myclick(' + i + ')">' + name + '</a><br>';

      i++;

      return marker;

    }





		// This function picks up the click and opens the corresponding info window

	function myclick(i) {

		GEvent.trigger(gmarkers[i], "click");

		if (_actiu!=null) { $("gog_" + _actiu).removeClass("actiu"); }

		$("gog_" + i).addClass("actiu");

		 _actiu = i;

	}



function loadMap(src){		

		if (GBrowserIsCompatible()) {

    // this variable will collect the html which will eventualkly be placed in the side_bar		      

    // arrays to hold copies of the markers used by the side_bar

    // because the function closure trick doesnt work there



    var i = 0;



    // create the map

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

    map.addControl(new GLargeMapControl());

    map.addControl(new GMapTypeControl());

    map.setCenter(new GLatLng(44.200000,5.200000), 6);
	 
	 //map.setCenter(new GLatLng(45.310000,6.800000), 6);
	 //maps.google.es/?ie=UTF8&ll=43.977005,2.131348&spn=5.186189,6.778564&t=h&z=7
    

    //map.setMapType(G_NORMAL_MAP);

		//map.setMapType(G_SATELLITE_MAP);

		map.setMapType(G_HYBRID_MAP);

		

    // Read the data from example.xml

    var request = GXmlHttp.create();

    request.open("GET", src, true);



    request.onreadystatechange = function() {

    if (request.readyState == 4) {

        

        //var xmlDoc = GXml.parse(request.responseXML);

        var xmlDoc = request.responseXML;

        // obtain the array of markers and loop through it

        

        var markers = xmlDoc.documentElement.getElementsByTagName("item");

        

        for (var i = 0; i < markers.length; i++) {

          // obtain the attribues of each marker

          var lat = parseFloat(markers[i].getAttribute("lat"));

          var lng = parseFloat(markers[i].getAttribute("long"));

          var id_item = markers[i].getAttribute("id");

          

          var point = new GLatLng(lat,lng);

          

          var label = markers[i].getElementsByTagName('label')[0].firstChild.data;

          var categoria = markers[i].getElementsByTagName('categoria')[0].firstChild.data;

          var urlLink = markers[i].getElementsByTagName('link')[0].firstChild.data;
			 
			 var descripcio = markers[i].getElementsByTagName('descripcio')[0].firstChild.data;

          var img = markers[i].getElementsByTagName("img");

          var imgSRC = "";

          var imgALT = "";

          if (img.length > 0){

							imgSRC = img[0].attributes.getNamedItem("src").value;

							imgALT = img[0].attributes.getNamedItem("alt").value;

					}

					

					//var marker = createMarker(point,{'title':label,'link':urlLink,'imgALT':imgALT,'imgSRC':imgSRC,'categoria':categoria}, i);
					var marker = createMarker(point,{'title':label,'link':urlLink,'imgALT':imgALT,'imgSRC':imgSRC,'categoria':categoria,'descripcio':descripcio}, i);

          

          map.addOverlay(marker);

        }

      }

    }

    request.send(null);

  }



  else {

    alert("Sorry, the Google Maps API is not compatible with this browser");

  }

    }


