
/****** Calcular cuanto se ha desplazado el scroll de la pantalla ******/

function calcularScroll(){
    var x,y;
    if (self.pageYOffset) // all except Explorer
    {
    	x = self.pageXOffset;
    	y = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    	// Explorer 6 Strict
    {
    	x = document.documentElement.scrollLeft;
    	y = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
    	x = document.body.scrollLeft;
    	y = document.body.scrollTop;
    }
    
    resultado=new Array(x,y);
    
    return resultado;

}

/****** Comprueba si el navegador es Internet Explorer ******/
function esIE(){
    var agt=navigator.userAgent.toLowerCase();
    return ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
}

/****** Registra un evento sobre un objeto (multi-plataforma) ******/

function anyadirEvento(objeto,evento,funcion){
	try{
		objeto.addEventListener(evento,funcion,false);
		return true;
	}catch(e){
		try{
			objeto.attachEvent("on"+evento,funcion);
			return true;
		}catch(e){
			return false;
		}
	}
}

/***** Altera la opcidad de un elemento ******/

function cambiarOpacidad(objeto,op){    
	objeto.style.filter="alpha(opacity="+op+")";
	objeto.style.MozOpacity=op/100;
	objeto.style.opacity=op/100;
}

/********Clase ventanaEmergente**********
texto_id = id del div que contiene el HTML a mostrar en la ventana
x,y posicion de la pantalla donde se muestra la ventana
minancho, minalto: dimensiones minimas de la ventana (se alarga para  que quepa el texto)
****************************************/
    function ventanaEmergente(texto_id,x,y,minancho,minalto,titulo){
        if (document.getElementById('emergente')){
            quitarDiv(document.getElementById('emergente'));
        }
        this.IE=esIE();
        this.minancho=minancho;
        this.minalto=minalto;
        this.sumaX=minancho/minalto*10;
        this.sumaY=10;
        this.ancho=0;
        this.alto=0;
        this.interv=null;
        this.desplegado=false;
        this.detalle=document.createElement("div");
        this.detalle.setAttribute("class","detalle");
        this.detalle.setAttribute("className","detalle");
        this.detalle.setAttribute("id","emergente");
        this.detalle.style.width="0px";
        this.detalle.style.minHeight="0px";
        if (IE){
            this.detalle.style.height="0px";
        }

        this.despl=calcularScroll();
        
        this.detalle.style.top=y+this.despl[1]+"px";
        this.detalle.style.left=x+this.despl[0]+"px";
        
        //creamos la barra del título;
        this.barratitulo=document.createElement("div");
        this.barratitulo.setAttribute("class","barradesc");
        this.barratitulo.setAttribute("className","barradesc");
        
        //creamos el aspa y la añadimos
        this.aspa=document.createElement("img");
        this.aspa.setAttribute("src","/images/iconos/aspa.gif");
        this.aspa.setAttribute("class","aspa");
        this.aspa.setAttribute("className","aspa");
        this.aspa.setAttribute("onclick","quitarDiv(this.parentNode.parentNode)");
        if (IE){
            this.aspa.onclick=quitarDiv;
        }
        
        this.barratitulo.appendChild(this.aspa);
        
        //creamos el titulo y lo añadimos al agrandar
        this.etiquetatitulo=document.createElement("span");
        this.etiquetatitulo.style.maxWidth=(minancho-50)+"px";
        this.titulov=document.createTextNode(document.getElementById(texto_id).title);

        
        this.barratitulo.appendChild(this.etiquetatitulo);
        
        

        
        //creamos el contenedor del texto
        this.contenido=document.createElement("div");
        this.contenido.setAttribute("class","contenidotexto desarrollo");
        this.contenido.setAttribute("className","contenidotexto desarrollo");
        this.contenido.style.width=(this.minancho-50)+'px';
        this.contenido.innerHTML=document.getElementById(texto_id).innerHTML;
        
        this.detalle.appendChild(this.barratitulo);
                
        this.id_texto=texto_id;
        document.getElementById('centro').appendChild(this.detalle);  
        this.interv=window.setInterval("agrandarDiv()",1);

        this.agrandarDiv=function(){
            if (this.ancho< this.minancho){
                this.detalle.style.width=this.ancho+"px";
                this.detalle.style.minHeight=this.alto+"px";
                if (IE){
                    this.detalle.style.height=this.alto+"px";
                }
                this.ancho+=sumaX;
                this.alto+=sumaY;
            }else{
                clearInterval(this.interv);
                desplegado=true;
              //  detalle.innerHTML=document.getElementById(id_texto).innerHTML;
                      this.etiquetatitulo.appendChild(this.titulov);
                this.detalle.appendChild(this.contenido);
            }
        }
        
}        
    
function quitarDiv(detalle){
    if (IE && !detalle) detalle=this.parentNode.parentNode;
    if (detalle.parentNode){
          detalle.style.display='none';
          detalle.innerHTML='';
          detalle.parentNode.removeChild(detalle);
          desplegado=false;
          ancho=0;
          alto=0;
    }
}
    