var map,point,marker;
var gdir;
var geocoder = null;
var addressMarker;

var icon = new GIcon();
icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(12, 20);

/*Sede (Pamplona)*/
	var Mapa0 = new Object();
		 Mapa0.MId="map";
		 Mapa0.MLat = 42.812797;
 		 Mapa0.MLng = -1.660116;	 
		 Mapa0.MZoom = 14;
	var Punto0 = new Object();
		 Punto0.PLat = -1.660116;
		 Punto0.PLng = 42.812797;
		 Punto0.PIcon = icon;
		 Punto0.PTab1="Nilsa";
		 Punto0.PTab2="Como llegar";
		 Punto0.PTab1Info="<p>Direcci&oacute;n<br /> Avenida Bara&ntilde;ain 22, bajo.<br /> 31008 Pamplona <br /><a href='mailto:info@nilsa.es'>info@nilsa.es</a></p><br />";
		 Punto0.PTab2Info="<p class='pGoogle'>Ej.:  Calle las delicias, Zaragoza </p><form action='http://maps.google.es/maps' method='get' target='_blank'><input type='text' name='saddr' id='saddr' class='inpuGoogle'/><input type='submit' class='btn' value='Enviar' /><input type='hidden' name='daddr' id='daddr' value='42.812797,-1.660116' class='oculto' /><br class='clear' /></form>";



/*Oficina en Madrid */
var Mapa1 = new Object();
		 Mapa1.MId="map1";
		 Mapa1.MLat = 42.059553;
 		 Mapa1.MLng = -1.598082;	 
		 Mapa1.MZoom = 14;
	var Punto1 = new Object();
		 Punto1.PLat = -1.598082;
		 Punto1.PLng = 42.059553;
		 Punto1.PIcon = icon;
		 Punto1.PTab1="Nilsa";
		 Punto1.PTab2="Como llegar";
		 Punto1.PTab1Info="<p>Direcci&oacute;n<br /> Avenida Zaragoza 78-80<br /> 31500 Tudela<br /> <a href='mailto:info@nilsa.es'>info@nilsa.es</a></p><br />";
		 Punto1.PTab2Info="<p class='pGoogle'>Ej.:  Calle las delicias, Zaragoza </p><form action='http://maps.google.es/maps' method='get' target='_blank'><input type='text' name='saddr' id='saddr' class='inpuGoogle'/><input type='submit' class='btn' value='Enviar' /><input type='hidden' name='daddr' id='daddr' value='42.059553,-1.598082' class='oculto' /><br class='clear' /></form>";





function crear_mapa(Mapa){
	//Map
	map = new GMap2(document.getElementById(Mapa.MId));
	map.setCenter(new GLatLng(Mapa.MLat,Mapa.MLng), Mapa.MZoom);
	//map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl(1));
}

function crear_punto(Punto, numero_punto){
	// Emplazar marcadores
	if(numero_punto==1){
		point = new GPoint(Punto.PLat,Punto.PLng);
		marker = new GMarker(point, Punto.PIcon);
		map.addOverlay(marker);
		GEvent.addListener(marker, "click", function() {
						   var html, html2
							map.savePosition();
							html = Punto.PTab1Info;
								html2 =	Punto.PTab2Info;
				
							var infoTabs = [
							new GInfoWindowTab(Punto.PTab1, html),
							new GInfoWindowTab(Punto.PTab2,html2)
							];
							marker.openInfoWindowTabsHtml(infoTabs);
						 });
	}
	
	if(numero_punto==2){
		point1 = new GPoint(Punto.PLat,Punto.PLng);
		marker1 = new GMarker(point1, Punto.PIcon);
		map.addOverlay(marker1);
		GEvent.addListener(marker1, "click", function() {
						   var html, html2
							map.savePosition();
							html = Punto.PTab1Info;
								html2 =	Punto.PTab2Info;
				
							var infoTabs = [
							new GInfoWindowTab(Punto.PTab1, html),
							new GInfoWindowTab(Punto.PTab2,html2)
							];
							marker1.openInfoWindowTabsHtml(infoTabs);
						 });
	}
	
	if(numero_punto==3){
		point2 = new GPoint(Punto.PLat,Punto.PLng);
		marker2 = new GMarker(point2, Punto.PIcon);
		map.addOverlay(marker2);
		GEvent.addListener(marker2, "click", function() {
						   var html, html2
							map.savePosition();
							html = Punto.PTab1Info;
								html2 =	Punto.PTab2Info;
				
							var infoTabs = [
							new GInfoWindowTab(Punto.PTab1, html),
							new GInfoWindowTab(Punto.PTab2,html2)
							];
							marker2.openInfoWindowTabsHtml(infoTabs);
						 });
	}
	
	if(numero_punto==4){
		point3 = new GPoint(Punto.PLat,Punto.PLng);
		marker3 = new GMarker(point3, Punto.PIcon);
		map.addOverlay(marker3);
		GEvent.addListener(marker3, "click", function() {
						   var html, html2
							map.savePosition();
							html = Punto.PTab1Info;
								html2 =	Punto.PTab2Info;
				
							var infoTabs = [
							new GInfoWindowTab(Punto.PTab1, html),
							new GInfoWindowTab(Punto.PTab2,html2)
							];
							marker3.openInfoWindowTabsHtml(infoTabs);
						 });
	}
}


function mostrar_mapa(Mapa){
			map.panTo(new GLatLng(Mapa.MLat, Mapa.MLng));
}
function mostrar_punto(Punto){
	marker.setPoint(new GLatLng(Punto.PLat,Punto.PLng));
	GEvent.addListener(marker, "click", function() {
                       var html, html2
						map.savePosition();
						html = Punto.PTab1Info;
							html2 =	Punto.PTab2Info;
			
						var infoTabs = [
						new GInfoWindowTab(Punto.PTab1, html),
						new GInfoWindowTab(Punto.PTab2,html2)
						];
						marker.openInfoWindowTabsHtml(infoTabs);
                     });
	crear_punto(Punto);
}