// 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/ubicacion/logoabertis.png' alt='logoAbertis' style='margin-left:-10px;width:65px;height:36px;'/><h4 style='color:#FF8C0B;font: 12px Verdana;font-weight:bold;'>Abertis Infraestructuras, S.A.</h4><p style='color:#10364D;'>Avinguda del Parc Logístic, 12-20<br/>08040 Barcelona<br/>Tel. 932 305 000<br/>Fax 932 305 001<br/><a href='mailto:abertis@abertis.com'>abertis@abertis.com</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/ubicacion/logoabertis.png";
		icon.iconSize = new GSize(65, 36);
		icon.iconAnchor = new GPoint(0, 36);
		icon.shadowSize= new GSize(65, 36);
		icon.transparent="img/ubicacion/logoabertis_transp.png";
		icon.imageMap=new Array(0,0,65,0,65,36,0,36);
	});
	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=-615;
	slideInter=window.setInterval("altoFlash()", 25);
}

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

function altoFlash() {
	var o=document.getElementById("links");
	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);
    }
}

$().ready(function(){
	initialize();
});

