function getAbsoluteElementPosition(element) {
  if (typeof element == "string")
    element = document.getElementById(element)
    
  if (!element) return { top:0,left:0 };
  
  var y = 0;
  var x = 0;
  while (element.offsetParent) {
    x += element.offsetLeft;
    y += element.offsetTop;
    element = element.offsetParent;
  }
  return {top:y,left:x};
}


var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousedown = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY;// + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  

}
//  End -->




function oculta_bocadillo(id){
	document.getElementById(id).style.visibility= "hidden";
}
function muestra_bocadillo(id, id2, id3, lado){
	document.getElementById(id).style.top = '0px';
	document.getElementById(id).style.left = '0px';
	
	//var elemento = document.getElementById(id2);
	//Calculo las coordenadas del cursor al pulsar el boton del raton
   // getMouseXY()
	
	//Averiguo el tamaño de la capa a mostrar
		var anchoCapa = document.getElementById(id).offsetWidth;
		var altoCapa=   document.getElementById(id).offsetHeight;	
				
	//var elemento_fin = document.getElementById(id3);
  var pos_fin = getAbsoluteElementPosition(document.getElementById(id2));
	

		
	//var pos_x=left_pos;
	//var pos_y=tempY - pos_fin.top - 10;
	
/*
Para averiguar donde empiezo a dibujar la capa de la salida, resto a las coordenadas de pulsacion del 
ratón el ancho y alto de la capa a mostrar, la x tiene un + 50 porque la capa debe ser un poco más ancha que
lo que realmente se ve.
*/
	//alert(pos_fin.top);
	var pos_y = pos_fin.top- altoCapa + 15;//tempY - altoCapa;
	
	if (lado=='izq'){
		var pos_x = tempX - anchoCapa + 50;
	}
	else if(lado=='dcha'){
		var pos_x = tempX - 50;		
	}
	else if(lado=='centro'){
		var pos_x = tempX - (anchoCapa/2 )-20;	
	}	
	else if(lado=='dchaFoto'){
		var pos_x = tempX - 50;	
	}	
	//if (lado=='dcha'){ var left_pos = tempX + 65; }	
		
	//var navegador = navigator.appName
	//if (navegador == "Microsoft Internet Explorer")
	//var pos_y=tempY - pos_fin.top - 100;
	

		
		
	//alert("ancho=" + ancho + "  alto=" + alto);
	
	document.getElementById(id).style.top = pos_y + 'px';
	document.getElementById(id).style.left = pos_x + 'px';
	document.getElementById(id).style.visibility = "visible";
}

function imprimir (id) {
	var y_anterior =   document.getElementById(id).offsetTop;
	var x_anterior = document.getElementById(id).offsetLeft;
	document.getElementById(id).style.top = '0px';
	document.getElementById(id).style.left = '0px';
	print();
	document.getElementById(id).style.top = y_anterior + 'px';
	document.getElementById(id).style.left = x_anterior + 'px';
}

function alto_bocadillo_home (id) {
            var altoCapa=document.getElementById(id).offsetHeight;
            var anchoCapa=document.getElementById(id).offsetWidth;
            var alto_max_capa=500;
            var ancho_max_capa=800;
            if (altoCapa>alto_max_capa){
                                   document.getElementById(id).style.height = alto_max_capa + 'px';
                                   document.getElementById(id).style.overflow = 'auto';
            }
            if (anchoCapa>ancho_max_capa){
                                   document.getElementById(id).style.width = ancho_max_capa + 'px';
                                   document.getElementById(id).style.overflow = 'auto';
            }
}


function muestra_bocadillo_home(id, id2){
	alto_bocadillo_home(id2);
	document.getElementById(id).style.visibility = "visible";
	
}
function oculta_bocadillo_home(id, id2){
	document.getElementById(id).style.visibility = "hidden";
	//alto_bocadillo_home(id2);
	
}