//
//  googleMaps
//
//  Created by Iban Moreno on 2007-08-31.
//  Copyright (c) 2007 __TheMovie__. All rights reserved.
//

var map;
var geocoder;
var address;
var direcciones;
var recorrido;
//ZOOM inicial
var globalZoom = 6;
//DIRECCIONES
var st_direccion = "Barkaiztegi Bidea 42, 20014, san sebastian, guipuzcoa, spain";
var st_direccion_html = "<font size='1.0'>BARKAIZTEGI<br/>P&ordm; de Barkaiztegi, 42 MARTUTENE<br/>20014 DONOSTIA-SAN SEBASTI&Aacute;N<br/>Tel.943 451 304-943 455 501<br/>Fax.943 460 195<br/><a href='http://maps.google.es/maps?f=d&saddr=Alameda+del+Boulevard+26,+20003+San+Sebasti%C3%A1n,+Spain&daddr=Camino+de+Okendotegi+%4043.293795,+-1.956616+to:43.293614,-1.956897+to:Carretera+desconocida+%4043.293187,+-1.958925&hl=es&geocode=%3BFWOclAId-CTi_w%3B%3BFQOalAId8xvi_w&mra=dpe&mrcr=0&mrsp=2&sz=17&via=1,2&sll=43.293388,-1.957755&sspn=0.005622,0.013089&ie=UTF8&z=17 target='_blank'>Como llegar</a></font>";
//<![CDATA[

//Crea mapa
function load() {
  //si el navegador es compatible
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
	recorrido = document.getElementById("recorrido");
	direcciones = new GDirections(map,recorrido);
	//controles
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl());
	resituaMapa(st_direccion, 14);
	}
}

//Crea marca standard
function createMarker(point, number) { 
	var marker = new GMarker(point,G_DEFAULT_ICON);
	GEvent.addListener(marker, "click", function() {
 		marker.openInfoWindowHtml(st_direccion_html);	
  	});
return marker;
}

//Direccion a coordenadas
function resituaMapa(direccion, zoom)
{
	globalZoom = zoom;
	geocoder = new GClientGeocoder();
	address = direccion;
	geocoder.getLocations(address, addToMap);
	//map.setCenter(new GLatLng(43.293356494207856,-1.9592070583894383), 12);
	var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var lngSpan = northEast.lng() - southWest.lng();
	var latSpan = northEast.lat() - southWest.lat();
	var point = new GLatLng(43.293356494207856,-1.9592070583894383);
	map.addOverlay(createMarker(point, 1));
}
GEvent.addListener(map, 'click', function mapClick(marker,point){
	if(!marker)
	{
		oLat = document.getElementById("lat");
		oLat.value = point.y;
		oLon = document.getElementById("lon");
		oLon.value = point.x;
		oZoom = document.getElementById("zoom");
	}
});
function addToMap(response)
{
	// Retrieve the object
	place = response.Placemark[0];
	point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
	map.setCenter(point, globalZoom);
	map.addOverlay(createMarker(point, 1));
}
function addToMapR(response)
{
	// Retrieve the object
	place = response.Placemark[0];
	point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
	map.setCenter(point, globalZoom);
	map.addOverlay(createMarker(point, 1));
}
//Resitua recorrido
function resituaRecorrido (direccion, zoom){
	globalZoom = zoom;
	geocoder = new GClientGeocoder();
	address = direccion;
	geocoder.getLocations(new GLatLng(43.293356494207856,-1.9592070583894383), addToMapR);
}
//SITUACION ACCESOS UBICACION
function map_situacion (){
	direcciones.clear();
	limpiaVentanas();
	resituaMapa(st_direccion, 6);
}
function map_ubicacion (){
	direcciones.clear();
	limpiaVentanas();
	resituaRecorrido(st_direccion, 16);
}
function map_accesos_bil (){
	limpiaVentanas();
	//map.setZoom(14);
	direcciones.clear();
	direcciones.load("from:bilbao, vizcaya, spain to: 43.293356494207856,-1.9592070583894383", {preserveViewport: true});
	resituaRecorrido(st_direccion, 14);
}
function map_accesos_ss (){
	limpiaVentanas();
	//map.setZoom(14);
	direcciones.clear();
	direcciones.load("from:san sebastian, guipuzcoa, spain to: 43.293356494207856,-1.9592070583894383", {preserveViewport: true});
	resituaRecorrido(st_direccion, 14);
}
function map_accesos_pam (){
	limpiaVentanas();
	//map.setZoom(14);
	direcciones.clear();
	direcciones.load("from:pamplona, navarra, spain to: 43.293356494207856,-1.9592070583894383", {preserveViewport: true});
	resituaMapa(st_direccion, 14);
}
function map_accesos_vit (){
	limpiaVentanas();
	//map.setZoom(14);
	direcciones.clear();
	direcciones.load("from:vitoria, alava, spain to: 43.293356494207856,-1.9592070583894383", {preserveViewport: true});
	resituaMapa(st_direccion, 14);
}
function map_accesos_bay (){
	limpiaVentanas();
	//map.setZoom(14);
	direcciones.clear();
	direcciones.load("from:bayonne, france to: 43.293356494207856,-1.9592070583894383", {preserveViewport: true});
	resituaMapa(st_direccion, 14);
}

function limpiaVentanas (){
	map.clearOverlays();
}
//
//]]>