 
    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    var idioma="es";
    var direccion;
    var direcciones="hola";

				// this initialises the demo scollpanes on the page.
    	
	
    function peticionMapa(){
    	direccion=$('.direccion').val();
    	var par="direccion="+direccion;
    	$('#contenido_donde').html('<table border="0"><tr><td><img src="images/loading.gif" alt="cargando" border="0" /></td></tr><tr><td><strong>Cargando mapa...</strong></td></tr></table>');
    	$.post('requestMapa.php', par, respuestaMapa);
    	
    	return false;
    }
    
    function respuestaMapa(response){
    	$('#contenido_donde').html(response);
    	
    	$('#contenido_donde').show('fast');
    	
    	$('#leftButton').remove();
    	$('#rightButton').remove();
    	
    	initialize(direccion);
    	
    }

    function initialize(direccionFrom) {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("mapa"));
        map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		
        gdir = new GDirections(map, document.getElementById("direcciones"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        
        setDirections(direccionFrom, "Av del Locutor Vicente Hipolito @38.37519021956498,-0.4243040084838867");
      }
    }
    
    
    function setDirections(fromAddress, toAddress) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": idioma });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		   alert("Lo sentimos no se ha encontrado un resultado para la direcci"+'\u00f3'+"n introducida. Intentelo con alguna mas conocida. \n Si el error persiste pruebe antes de que Google Maps si que encuentra la direcci"+'\u00f3'+"n que intenta introducir. GRACIAS.");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("Ha ocurrido un error en el servidor. Por favor, vuelva a intentarlo pasado un rato. GRACIAS");
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("Error con la conexi"+'\u00f3'+"n con Google. Fuera de servicio, pongase en contacto con el Webmaster.");

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("Lo sentimos no se ha encontrado un resultado para la direcci"+'\u00f3'+"n introducida. Puede probar con alguna mas conocida.");
	    
	   else alert("Error desconocido. Vuelva a intentarlo.");
	   
	}

	function onGDirectionsLoad(){ 
		
	}