/*----------------------
    Site-wide Scripts
------------------------*/
// Create event listeners
if (window.addEventListener) {
	window.addEventListener("load", init, false)
} else if (window.attachEvent) {
	window.attachEvent("onload", init);
}

/*--------------------
    Initialize page
----------------------*/
function init(e) {
	decodeEmails();
}

/*-------------------------------------------------
	Create working hyperlinks for encoded e-mails
---------------------------------------------------*/
function decodeEmails() {
	// Check browser compatibility
	if (!document.getElementsByTagName || !document.createElement) return false;
	
	// Loop through <span> elements and create hyperlinks for e-mail addresses
	var spans = document.getElementsByTagName("span");
	
	for (var n = 0; n < spans.length; n++) {
		if (spans[n].className == "encoded-email") {
			// Create <a> element and child text node
			var email     = spans[n].firstChild.nodeValue.replace(" (at) ", "@").replace(" (dot) ", ".");
			var hyperlink = document.createElement("a");
			var link_text = document.createTextNode(email);
			
			// Set <a> properties
			hyperlink.href  = "mailto:" + email;
			hyperlink.title = "Send an e-mail using your default e-mail client";
			hyperlink.appendChild(link_text);
			
			// Replace encoded e-mail with <a> element
			spans[n].replaceChild(hyperlink, spans[n].firstChild);
		}
	}
}