/* Simon Willison's addLoadEvent function allows you to stack up 'window.onload' events 
without them stepping on each other's toes. 
It's explained here - http://www.sitepoint.com/blog-post-view.php?id=171578 */

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


/* Esta es la funcion acutal del popup se usa todavia en partes del sitio asi que la mantenemos */

function acpopup(strURL,strType,strHeight,strWidth) {
var strOptions="";
if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
window.open(strURL, '', strOptions);
}


/* new accessible, unobtrusive popup code */

function windowLinks() {                      // crea una nueva funcion llamada windowLink(); 
    if(!document.getElementsByTagName) {      // Solo ejecuta la funcion en navegadores que
         return;                              // entienden 'getElementsByTagName' - los nuevos
    }
	
    var anchors = document.getElementsByTagName("a"); // recoje todos los links y los mete en un array llamado 'anchors'
    for (var i = 0; i < anchors.length; i++) {        // comienza un bucle para recorrer ese array 
         var anchor = anchors[i];                     // toma el siguiente link y lo copya a 'anchor' para trabajar con el
         var relIndex = anchor.rel;                   // toma el valosr de su atributo 'REL' 
		 if (relIndex){                               // tiene un valor para REL?...
		 var relSplit = relIndex.split("|");          
		 /* si lo tiene, buscar '|' que divide el valor en  
		 array - relSplit[0], relSplit[1], relSplit[2], etc . Si no hay ningun
		  '|', todo el valor se envia a relSplit[0] */
		 
/*atributo target   XHTML */

		 if (relSplit[0] == "external") {       // Si el relSplit[0] es 'external'...
            anchor.target = "_blank";           // entonces se le pone el 'target' a '_blank'
			anchor.className = "external";      // entonces se le agrega la clase css  
			anchor.title = "Carga en nueva ventana: "+ anchor.href;  
			// y se le da un nuevo atributo de title para advertir a los usuarios que se lanza una nueva ventana
			
/* Elegantly degrading window code */

   			} else if (relSplit[0] == "popup") {      // si  relSplit[0] es 'popup'...
			anchor.className = "popup";               // se le aņade la clase CSS 
			anchor.title = "Carga en un popup"; // Se le cambia el title por uno de aviso
			anchor.popupWidth = relSplit[1];          // se aņade el ancho del popup
			anchor.popupHeight = relSplit[2];          // se aņade el alto del popup
	        anchor.onclick = function() {acpopup(this.href,'console',this.popupWidth,this.popupHeight);return false;};
			// se le mete toda la informacion al la funcion original de lanzamiento del popup (acpopup) 
			}
		}
	  }
} 

addLoadEvent(function() {
	windowLinks();	// ejecuta nuestra nueva funcion tan pronto como la pagina cargue. 
	//otherFunctions();
	//goHere();
});
  
