/* This handy addLoadEvent function from Simon Willison 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();
    }
  }
}


/* This is our old popup function - parts of the site still use it, so I need to keep it */
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() {
    if(!document.getElementsByTagName) {
         return;
    }
	
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
         var anchor = anchors[i];
         var relIndex = anchor.rel;
		 if (relIndex){
		 var relSplit = relIndex.split("|");    // Split our REL value into parts 
/* XHTML compliant target attribute */
		 if (relSplit[0] == "external") {       // If the REL=external...
            anchor.target = "_blank";           // set its 'target' attribute to '_blank'
			anchor.className = "external";      // attach a CSS class to it to allow us to style it
			anchor.title = "Open in new window: "+ anchor.href;  // Add a new title attribute to warn the users of a new window
			
/* XHTML compliant popup attribute */
   			} else if (relSplit[0] == "popup") { // If the REL=popup...
			anchor.className = "popup";          // attach a CSS class to it to allow us to style it
			anchor.title = "Opens in a Popup Window"; // Add a new title attribute to warn the users of a new window
			anchor.popupWidth = relSplit[1]; 
			anchor.popupHeight = relSplit[2];
	        anchor.onclick = function() {acpopup(this.href,'console',this.popupWidth,this.popupHeight);return false;};
			}
		}
	   }
} 

addLoadEvent(function() {
	windowLinks();	
	//otherFunctions();
	//goHere();
});

