/* Javascripts para Itelazpi TDT desarrollados por Deusto Sistemas */

/* Estados normal y over para imagenes de mapas */
function mostrarCapa(nombreCapa) {document.getElementById(nombreCapa).style.visibility='visible'}
function ocultarCapa(nombreCapa) {document.getElementById(nombreCapa).style.visibility='hidden'}

/* Funcion para cambio de visualizacion cobertura y semaforico */
function cambiaMapa(territorio,municipio,tipo) {
document.getElementById('capaMapasDetalle').style.display='block';	
urlImagen= '../../../../../images/mapasDinamicos/'+territorio+'/'+municipio+'/'+tipo+municipio+'.gif' ;
ruta="url("+urlImagen+")";
document.getElementById('mapaGrande').style.backgroundImage=ruta;
document.getElementById('imagenPequena').src=urlImagen; 
  if (tipo=='cobertura') {document.getElementById('leyendaCobertura').style.display='block'; document.getElementById('leyendaSemaforico').style.display='none'}
  if (tipo=='semaforico') {document.getElementById('leyendaSemaforico').style.display='block'; document.getElementById('leyendaCobertura').style.display='none'}
}
/* Funcion para cerrar la capa de detalle de mapas */
function cerrarMapaDetalle() {document.getElementById('capaMapasDetalle').style.display='none'};

/* Sistema de marcador con zoom para mapas */
var mDown = false;
var offsetX=0;
var offsetY=0;
function init() {
	document.onmousedown = captureMouseDown;
	document.onmousemove = captureMouseMove;
	document.onmouseup = captureMouseUp;
	document.getElementById("marcador").onmousedown = captureOffset;
	document.getElementById("marcador").style.top = "0";
	document.getElementById("marcador").style.left = "0";
}

function captureOffset(e) {
	x = parseInt(document.getElementById("marcador").style.left);
	y = parseInt(document.getElementById("marcador").style.top);
	if(document.all) {offsetX=window.event.clientX - x;	offsetY=window.event.clientY - y} 
	else {offsetX = e.pageX - x; offsetY = e.pageY - y}
}

function captureMouseDown() {mDown=true}
function captureMouseUp() {mDown = false}

function captureMouseMove(e) {	
	if(!mDown)return;
	x = document.all?window.event.clientX - offsetX:e.pageX - offsetX;
	y = document.all?window.event.clientY - offsetY:e.pageY - offsetY;
	
	if(x<=-1 || x>=175 || y<=-1 || y >= 105)return;
	document.getElementById("marcador").style.left = x + "px";	
	document.getElementById("marcador").style.top = y + "px";

	x2 = parseInt(document.getElementById("marcador").style.left);
	y2 = parseInt(document.getElementById("marcador").style.top);
	
	if (document.body.innerHTML.indexOf('alava')!=-1) {x2 = (x2 - (x2*2))*3.9; y2 = (y2 - (y2*2))*4}
	else {x2 = (x2 - (x2*2))*2; y2 = (y2 - (y2*2))*2};	
	
	document.getElementById("mapaGrande").style.backgroundPosition = x2 + "px " + y2 + "px";
}

window.onload=function() {if (document.getElementById('capaMapasDetalle')) {init()}}