/***** Añade eventos a los elementos de la página definidos en el vector "etiquetas" de la página de modo que al pasar por encima aparezca una descripción según su atributo "title" *****/
//Requiere funciones del archivo dom.js

function Ayuda(){	
	var etiquetas=new Array('A','IMG');
	var contenido={};
	for (q=0;q<etiquetas.length;q++){
		var enlaces=document.getElementsByTagName(etiquetas[q]);
		for(k=0;k<enlaces.length;k++){    
			tit=enlaces[k].title;
		//	if (tit=="") tit=enlaces[k].alt;
			if (tit){
				enlaces[k].removeAttribute('title');  
				enlaces[k].removeAttribute('alt');
				enlaces[k].longdesc=tit;
				try{
					enlaces[k].firstChild.removeAttribute('title');
					enlaces[k].firstChild.removeAttribute('alt');
					enlaces[k].firstChild.longdesc=tit;
				}catch(ex){}
				enlaces[k].onmouseover=function(e){generarAyuda(this.longdesc,e)};
				enlaces[k].onmouseout=function(e){destruirAyuda(e)};
				enlaces[k].onmousemove=function(e){if (!document.getElementById('ayuda_contextual')) generarAyuda(this.longdesc,e);moverAyuda(e)};
			}
		}
	}
    /*Parche para solucinar un espacion en blanco en IE*/	
 /*   generarAyuda("",{clientX:0,clientY:0});
    setTimeout(destruirAyuda,100);*/
    /******************************************/
}

function generarAyuda(titulo,e){
          if (titulo==undefined) return;
          if (!e) var e = window.event;
          var relTarg;
/*try{
	if (!e) var e = window.event;
	if (e.relatedTarget) relTarg = e.relatedTarget;
	else if (e.fromElement) relTarg = e.fromElement;
	var reltg=relTarg;
	while (reltg.nodeName != 'BODY'){
              	if(reltg.longdesc==titulo){ return;}
            	reltg= reltg.parentNode;
            }
}catch(ex){}*/

        if(document.getElementById('ayuda_contextual')) document.getElementById('ayuda_contextual').parentNode.removeChild(document.getElementById('ayuda_contextual'));


    this.caja=document.createElement("div");
    this.caja.setAttribute("id","ayuda_contextual");
    this.despl=calcularScroll();  	
    this.caja.style.top=e.clientY+this.despl[1]+"px";
    this.caja.style.left=e.clientX+this.despl[0]+"px";
    this.frecuencia=60;
    this.opacidad=0;
    this.aumento=0;
    this.caja.innerHTML=titulo;
    cambiarOpacidad(this.caja,this.opacidad);
    document.getElementsByTagName('BODY')[0].appendChild(this.caja);
    
    try{
        if(document.getElementById('ayuda_contextual').clientWidth>250){
              document.getElementById('ayuda_contextual').style.width="250px";
        }
    }catch(ex){}
    
	this.aparecer=function(){	
	    if (this.opacidad<75){	
	        this.opacidad+=this.aumento;
	           if (this.opacidad<1){
	                this.aumento+=0.05;
	           }else{
	        	  this.aumento+=1;
	           }
	        cambiarOpacidad(this.caja,this.opacidad);
	    }else{
	        this.opacidad=75;
	        window.clearInterval(this.tempo);
	    }
	}
	
	this.setInterval("this.aparecer()",this.frecuencia);
	return false;
}

function destruirAyuda(e){
	try{
	           if (!e) var e = window.event;
            	var tg = (window.event) ? e.srcElement : e.target;
            	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
            	
            //	if (reltg.nodeName=="IMG") return;

            	
            	var reltg1=reltg;
            	while (reltg1 != tg && reltg1.nodeName != 'BODY'){
            		reltg1= reltg1.parentNode;
            	}
            	if (reltg1== tg) return;
            	
            	while (reltg != tg && tg.nodeName != 'BODY'){
            		tg= tg.parentNode;
            	}
            	if (reltg== tg && tg.longdesc) return;
                      	
		document.getElementById('ayuda_contextual').parentNode.removeChild(document.getElementById('ayuda_contextual'));
	}catch(e){}
}

function moverAyuda(e){
           if (!e) var e = window.event;
	try{
		this.despl=calcularScroll();  	
	    document.getElementById('ayuda_contextual').style.top=e.clientY+this.despl[1]+"px";
	    document.getElementById('ayuda_contextual').style.left=e.clientX+this.despl[0]+"px";
	}catch(e){}
}

generarAyuda.prototype=window;
anyadirEvento(window,"load",Ayuda);


