var RUTA_IMAGENES = "pages/img/{idioma}/aplicaciones/";
var ICONO_IMAGEN = RUTA_IMAGENES + "e.png";
var ICONO_SOMBRA = RUTA_IMAGENES + "sombra.png";

var icon = new GIcon();
icon.image = ICONO_IMAGEN;
icon.shadow = ICONO_SOMBRA;
icon.iconSize = new GSize(49, 52);
icon.shadowSize = new GSize(51, 42);
icon.iconAnchor = new GPoint(37, 59);
icon.infoWindowAnchor = new GPoint(31, 8);		    

var ZOOM_BASE = "17";
var ZOOM_MINIMO = "1";

//valores de alto y ancho del bocadillo. Ajustar en caso de necesidad
var MAX_HEIGHT = 170;
var MAX_WIDTH = 450;

/**
 * Pinta el mapa
 *
 * @param idioma  Idioma del portal
 */
function pintarMapa(idioma) {
	window.onload = function() {
	var capaMapa = document.getElementById("map");
//	capaMapa.className = "capa_mapa";
	if (GBrowserIsCompatible()) {
	
		var mapa = new GMap2(capaMapa);
        mapa.addControl(new GSmallMapControl());
        mapa.addControl(new GMapTypeControl());
        mapa.addControl(new GOverviewMapControl()); 
        mapa.addControl(new GScaleControl());
		        
        // Punto central (Conde Duque)
        var punto = new GLatLng(parseFloat(CENTRO_COORDX), 
        						parseFloat(CENTRO_COORDY));
        mapa.setCenter(punto, parseInt(ZOOM_BASE));
		var mgr = new GMarkerManager(mapa);
		
		icon.image = ICONO_IMAGEN.replace("{idioma}", idioma);
		icon.shadow = ICONO_SOMBRA.replace("{idioma}", idioma);
        // Marcadores
        var infoHTML = null;
        var marcador = null;

        // Información HTML del marcador
		infoHTML = obtenerInformacionPunto(arrayRecurso[0],arrayRecurso[1],arrayRecurso[2],arrayRecurso[3],arrayRecurso[4],arrayRecurso[5],arrayRecurso[6],arrayRecurso[7],arrayRecurso[8],arrayRecurso[9]);
 	    marcador = new GMarker(punto,icon);	
		addListener(marcador,infoHTML);
		mgr.addMarker(marcador,ZOOM_MINIMO);	
		
		var opts = new Object();
		opts.maxWidth = MAX_WIDTH;
		opts.maxHeight = MAX_HEIGHT;
		marcador.openInfoWindowHtml(infoHTML,opts);

		mapa.enableDoubleClickZoom(); 	//Activa el zoom con dobleclic
		mapa.enableContinuousZoom(); 	//Activa el Zoom suave
	}
	// Destruye los objetos
	punto = null;
	marcador = null;
	};
	window.onunload = function() {GUnload(); mapa = null;};
}

/**
 * Añade el listener para el evento de click (hace que salga un popup con info)
 *
 * @param marcador  El marker al que añadimos la información
 * @param infoHTML  El html a mostrar en el popup
 */
function addListener(marcador,infoHTML){
	GEvent.addListener(marcador, 'click', function() {
		var opts = new Object();
		opts.maxWidth = MAX_WIDTH;
		opts.maxHeight = MAX_HEIGHT;
		marcador.openInfoWindowHtml(infoHTML,opts);
	});				
}

/**
 * Compone el código HTML del bocadillo a partir
 * de la información proporcionada.
 *
 * @param nombre  Nombre del punto
 * @param tipoVia  Tipo de Vía del punto
 * @param nombreVia Via del punto
 * @param numeroVia  Número de Via del punto
 * @param cp  código postal del punto
 * @param telefono  teléfono del punto
 * @param metro  líneas de metro del punto
 * @param autobus  autobuses del punto
 * @param servicios  servicios del punto
 * @param web  web del punto
 */
function obtenerInformacionPunto(nombre, tipoVia, nombreVia,numeroVia, cp,telefono,metro,autobus,servicios,web) {
/*	var texto = "<ul class=\"item\">";
	if ((nombre != null) && (nombre != "") && (nombre != "undefined")) {
		texto += "<li><span>" + nombre + "</span></li>";
	}
	
	texto+="<li>" + "<strong>" + arrayTextos[0] + ": </strong>";
	if ((tipoVia != null) && (tipoVia != "") && (tipoVia != "undefined")) {
		texto += tipoVia + " " ;
	}
	if ((nombreVia != null) && (nombreVia != "") && (nombreVia != "undefined")) {
		texto += nombreVia + " ";
	}
	if ((numeroVia != null) && (numeroVia != "") && (numeroVia != "undefined")) {
		texto += numeroVia;
	}
	
	if ((cp != null) && (cp != "") && (cp != "undefined")) {
		texto += " , " + cp;
	}
	
    texto+="</li>";
	
	if ((telefono != null) && (telefono != "") && (telefono != "undefined")) {
		texto += "<li>"  + "<strong>" + arrayTextos[1] + ": </strong>" + telefono + "</li>";
	}
	if ((metro != null) && (metro != "") && (metro != "undefined")) {
		texto += "<li>" + "<strong>" + arrayTextos[2] + ": </strong>" + metro + "</li>";
	}
	if ((autobus != null) && (autobus != "") && (autobus != "undefined")) {
		texto += "<li>" + "<strong>" + arrayTextos[3] + ": </strong>" + autobus + "</li>";
	}
	if ((servicios != null) && (servicios != "") && (servicios != "undefined")) {
		texto += "<li>" + "<strong>" + arrayTextos[4] + ": </strong>" + servicios + "</li>";
	}
	if ((web != null) && (web != "") && (web != "undefined")) {
		texto += "<li>" + "<strong>" + arrayTextos[5] + ": </strong><a href=\"" + web + "\" onfocus=\"blur();\">" + web + "</a></li>";
		
	}
	
	texto += "</ul>";
*/	
	var texto = "<table>";
	if ((nombre != null) && (nombre != "") && (nombre != "undefined")) {
		texto += "<tr><th colspan=\"2\" class=\"nombre\">" + nombre + "</th></tr>";
	}
	
	texto+="<tr><td>" + "<strong>" + arrayTextos[0] + ": </strong></td><td>";
	if ((tipoVia != null) && (tipoVia != "") && (tipoVia != "undefined")) {
		texto += tipoVia + " " ;
	}
	if ((nombreVia != null) && (nombreVia != "") && (nombreVia != "undefined")) {
		texto += nombreVia + " ";
	}
	if ((numeroVia != null) && (numeroVia != "") && (numeroVia != "undefined")) {
		texto += numeroVia;
	}
	
	if ((cp != null) && (cp != "") && (cp != "undefined")) {
		texto += " , " + cp;
	}
	
    texto+="</td></tr>";
	
	if ((telefono != null) && (telefono != "") && (telefono != "undefined")) {
		texto += "<tr><td>"  + "<strong>" + arrayTextos[1] + ": </strong></td><td>" + telefono + "</td></tr>";
	}
	if ((metro != null) && (metro != "") && (metro != "undefined")) {
		texto += "<tr><td>" + "<strong>" + arrayTextos[2] + ": </strong></td><td>" + metro + "</td></tr>";
	}
	if ((autobus != null) && (autobus != "") && (autobus != "undefined")) {
		texto += "<tr><td>" + "<strong>" + arrayTextos[3] + ": </strong></td><td>" + autobus + "</td></tr>";
	}
	if ((servicios != null) && (servicios != "") && (servicios != "undefined")) {
		texto += "<tr><td>" + "<strong>" + arrayTextos[4] + ": </strong></td><td>" + servicios + "</td></tr>";
	}
	if ((web != null) && (web != "") && (web != "undefined")) {
		texto += "<tr><td>" + "<strong>" + arrayTextos[5] + ": </strong></td><td><a href=\"" + web + "\" onfocus=\"blur();\">" + web + "</a></td></tr>";
		
	}
	
	texto += "</table>";
	
	return texto;
}

