// Based on code from
// http://www.serve.com/apg/workshop/replacingTarget/

relLink = function() {

	// Fetch all the a elements in the document.
	var links = document.getElementsByTagName("a");
	
	// Loop through the a elements in reverse order
	// for speed.
	for (var i = links.length; i != 0; i--) {
		
		// Pull out the element for this iteration.
		var a = links[i-1];
		
		// If the element doesn't have an href, skip it.
		if (!a.href) continue;
	
		// If the element has a rel attribute that contains
		// "external" attach the onclick handler.
		if (a.rel && a.rel.indexOf("external") != -1) {
			a.onclick = PopWin;
			if (a.title == "") a.title = "Open link in new window";
		}
		
		// If the link is to a PDF, then set class of link to pdf
		if (a.href.substring(a.href.length - 4, a.href.length).toLowerCase() == ".pdf") {
			a.className = "pdf";
		}
	}
}

function PopWin(e) {

	// Accommodate IE's non-standard event handling.
	if (!e) var e = window.event;
	var a = e.target ? e.target : e.srcElement;

	// Open a new window with the link's href.
	var newwin = window.open(a.href);

	// The thought is that if the new window didn't
	// (popups blocked or whatever) we want to return
	// true so the link is follow normally. Not sure
	// if this works, but it doesn't seem to hinder.
	return !newwin;                               
}

// IE: attach event
if (window.attachEvent) window.attachEvent("onload", relLink);

// Others: attach event
if (window.addEventListener) window.addEventListener("load", relLink, false);
