//<![CDATA[

    var markerBarcelona;
    var infoTabsBarcelona;
    var markerMadrid;
    var infoTabsMadrid;
    var markerGalicia;
    var infoTabsGalicia;
    var markerPV;
    var infoTabsPV;
    var markerBaleares;
    var infoTabsBaleares;
    var markerAragon;
    var infoTabsAragon;
    var map;
    var geocoder;    
    
function load() {
 if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
//  map.setCenter(new GLatLng(40.46652, -3.73374), 5);  		//Madrid
		map.setCenter(new GLatLng(41.3875264674425, 2.15814602561295), 5);				//Barcelona
		geocoder = new GClientGeocoder();
		
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());

		// Creates a marker at the given point with the given number label
		/*
		function createMarker(point, number,text) {
		  var marker = new GMarker(point);
		  GEvent.addListener(marker, "click", function() {
		    marker.openInfoWindowHtml("<font face=Verdana size=1>" + texto + "</font>");
		  });
		  return marker;
		}
		*/
		
		//map.disableDragging();
		
		var icon = new GIcon();
		icon.image = "img/koala1.png";
		icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		//icon.iconSize = new GSize(30, 30);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(15, 60);
		//icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(1, 30);
		//icon.infoWindowAnchor = new GPoint(5, 1);

		// Our info window content
        infoTabsBarcelona = [
          new GInfoWindowTab("Servicios", "Asesoramiento, instalaci&oacute;n y mantenimiento<br />de equipos inform&aacute;ticos, redes, configuraciones.<BR />Servicio de Asisténcia Técnica (SAT)<br>Desarrollo y programaci&oacute;n web.<BR /><BR />Tel: <B>902 365 542</B>"),
          new GInfoWindowTab("Contacto", "<B>SEDE CENTRAL</B><BR />c/Muntaner 81 - 6º 2ª<br />08011 Barcelona<br /><br />Tel: <B>902 365 542</B>")          
        ];
        infoTabsMadrid = [
          new GInfoWindowTab("Servicios", "Asesoramiento, instalaci&oacute;n y mantenimiento<br />de equipos inform&aacute;ticos, redes, configuraciones.<BR />Servicio de Asisténcia Técnica (SAT)<br>Desarrollo y programaci&oacute;n web.<BR /><BR />Tel: <B>902 365 542</B>")
        ];
/*         infoTabsGalicia = [
          new GInfoWindowTab("Servicios", "Asesoramiento, instalaci&oacute;n y mantenimiento<br />de equipos inform&aacute;ticos, redes, configuraciones.<BR />Servicio de Asisténcia Técnica (SAT)<br>Desarrollo y programaci&oacute;n web.<BR /><BR />Tel: <B>902 365 542</B>")
        ];
         infoTabsPV = [
          new GInfoWindowTab("Servicios", "Asesoramiento, instalaci&oacute;n y mantenimiento<br />de equipos inform&aacute;ticos, redes, configuraciones.<BR />Servicio de Asisténcia Técnica (SAT)<br>Desarrollo y programaci&oacute;n web.<BR /><BR />Tel: <B>902 365 542</B>")
        ];
         infoTabsBaleares = [
          new GInfoWindowTab("Servicios", "Asesoramiento, instalaci&oacute;n y mantenimiento<br />de equipos inform&aacute;ticos, redes, configuraciones.<BR />Servicio de Asisténcia Técnica (SAT)<br>Desarrollo y programaci&oacute;n web.<BR /><BR />Tel: <B>902 365 542</B>")
        ];
         infoTabsAragon = [
          new GInfoWindowTab("Servicios", "Asesoramiento, instalaci&oacute;n y mantenimiento<br />de equipos inform&aacute;ticos, redes, configuraciones.<BR />Servicio de Asisténcia Técnica (SAT)<br>Desarrollo y programaci&oacute;n web.<BR /><BR />Tel: <B>902 365 542</B>")
        ];
*/        
        
        GEvent.addListener(map, "infowindowclose", function() {
//						if (map.getZoom() < 7) map.panTo(new GLatLng(40.46652, -3.73374));		//Madrid
						if (map.getZoom() < 7) map.panTo(new GLatLng(41.3875264674425, 2.15814602561295));			//Barcelona
				});
                
        
        // PONEMOS LOS MARCADORES
        // Barcelona
//        markerBarcelona = new GMarker(new GLatLng(41.40111, 2.18139),icon);
 //       markerBarcelona = new GMarker(new GLatLng(41.40111, 2.18139));
        markerBarcelona = new GMarker(new GLatLng(41.3875264674425, 2.15814602561295));
        GEvent.addListener(markerBarcelona, "click", function() {
          markerBarcelona.openInfoWindowTabsHtml(infoTabsBarcelona);
        });
        map.addOverlay(markerBarcelona);
                
        // Madrid
        markerMadrid = new GMarker(new GLatLng(40.46653, -3.72263));
        GEvent.addListener(markerMadrid, "click", function() {
          markerMadrid.openInfoWindowTabsHtml(infoTabsMadrid);
        });
        map.addOverlay(markerMadrid);
        
/*        // Galicia
        markerGalicia = new GMarker(new GLatLng(42.86122, -7.90271));
        GEvent.addListener(markerGalicia, "click", function() {
          markerGalicia.openInfoWindowTabsHtml(infoTabsGalicia);
        });
        map.addOverlay(markerGalicia);
        
        // PV
        markerPV = new GMarker(new GLatLng(43.11352, -2.58937));
        GEvent.addListener(markerPV, "click", function() {
          markerPV.openInfoWindowTabsHtml(infoTabsPV);
        });
        map.addOverlay(markerPV);
        
        // Baleares
        markerBaleares = new GMarker(new GLatLng(39.56192, 2.52977));
        GEvent.addListener(markerBaleares, "click", function() {
          markerBaleares.openInfoWindowTabsHtml(infoTabsBaleares);
        });
        map.addOverlay(markerBaleares);

        // Aragon
        markerAragon = new GMarker(new GLatLng(41.64777, -0.89124));
        GEvent.addListener(markerAragon, "click", function() {
          markerAragon.openInfoWindowTabsHtml(infoTabsAragon);
        });
        map.addOverlay(markerAragon);
*/	
		
		/*
		SW = 35.13630, 3.62389
		NE = 44.59076, 10.79038
		*/
      }
    }
    
    function openInfo(pais){
		eval("marker" + pais + ".openInfoWindowTabsHtml(infoTabs" + pais + ")");
    }

	// 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();
      if (!response || response.Status.code != 200) {
        alert("Lo sentimos, no se ha encontrado la dirección.");
      } 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 + '(' + place.AddressDetails.Country.CountryNameCode + ')');
      }
    }

    // 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() {
      var address = document.forms[0].q.value;
      geocoder.getLocations(address, addAddressToMap);
    }

   // findLocation() is used to enter the sample addresses into the form.
    function findLocation(address) {
      document.forms[0].q.value = address;
      showLocation();
    }

    //]]>
