// Create a directions object and register a map and DIV to hold the 
// resulting computed directions
var htmlAbertis="<div style='font: 11px Verdana, sans-serif;color:#10364D;'><img src='img/mapa/logo_AcesaAucat.gif' alt='logoAcesaAucat' style='margin-left:40px;'/> <br /><span style='color:#FF8C0B;font: 12px Verdana;font-weight:bold;'>Acesa Aucat.</span><br /><p style='color:#10364D;'>Avinguda del Parc Logístic, 12-20<br/>08040 Barcelona<br/>Atención 24 horas. 902 200 320<br/>Oficinas. 93 230 52 00<br/><a href='mailto:atencion.clientes@autopistas.com'>atencion.clientes@autopistas.com</a><br/><a href='mailto:correu@aucat.es'>correu@aucat.es</a></p></div>";
var map;
var directions;

function initialize() {

	//document.getElementById("ubicacion").style.height="422px"; Para versión flash

	map = new GMap2(document.getElementById("map_canvas"));
	map.enableScrollWheelZoom();
	map.enableDoubleClickZoom();
	map.setCenter(new GLatLng(48.25, 11.00), 4);
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());

	directions = new GDirections(map);
	GEvent.addListener(directions, "load", function() {
		var marker=directions.getMarker(1);
		var icon=marker.getIcon();
		icon.image="img/mapa/logo_acesa.gif";
		icon.iconSize = new GSize(69, 40);
		icon.iconAnchor = new GPoint(0, 40);
		icon.shadow = "img/mapa/shadow-logo_acesa.png";
		icon.shadowSize= new GSize(90, 40);
		icon.transparent="img/mapa/logoacesa_transp.png";
		icon.imageMap=new Array(0,0,69,0,69,40,0,40);
	});
	GEvent.addListener(directions, "addoverlay", function() {
		var marker=directions.getMarker(1);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(htmlAbertis);
		});
		//thisMovie("ubicacion").mapLoaded(true); Para versión flash
		showmap();
		map.setZoom(map.getBoundsZoomLevel(directions.getPolyline().getBounds()));
	});
	GEvent.addListener(directions, "error", handleErrors);
}

function setDireccion(from) {
	var to="41.340000,2.123888 ";
	directions.load("from:"+from+" to:"+to);
	document.getElementById("direct_link").href="http://maps.google.es/maps?saddr="+from+"&daddr="+to;
	document.getElementById("print_map").href="http://maps.google.es/maps?ie=UTF8&z=14&om=1&pw=2&saddr="+from+"&daddr="+to;
}

var slideInter;
var finH;
function showmap() {
	clearInterval(slideInter);
	finH=-550;
	slideInter=window.setInterval("altoFlash()", 25);
}

function hidemap() {
	finH=0;
	if(!slideInter) slideInter=window.setInterval("altoFlash()", 25);
}

function altoFlash() {
	var o=document.getElementById("links_mapa");
	var iniH=Number(o.style.marginTop.split("px").join(""));
	var mult=(finH-iniH)/7;
	o.style.display = "block";
	o.style.marginTop=Math.floor(iniH+mult)+"px";
	if (Math.abs(mult)<1) {
		o.style.marginTop=finH+"px";
		if (finH == 1) {
		    o.style.display = "none";
		}
		clearInterval(slideInter);
		slideInter=false;
	}
}

function checkForm() {
    var calle  = document.getElementById("calle" ).value;
    var numero = document.getElementById("numero").value;
    var ciudad = document.getElementById("ciudad").value;
    if(calle && ciudad) {
        setDireccion(calle + " " + numero + ", " + ciudad);
    } else {
        alert(rellenarCampos);
    }
}
