
/* -----------------------------------------------------------------------------------
 * Replaces the text " dot " and " at " in a string with the appropriate symbols and
 * converts the node to a link. If the node has a title attribute that is used as the
 * text for the link.
 * This allows email addresses to be written in the page without fear of spamming but
 * still allowing people to click on the link.
 * Spam bots *shouldn't* be able to read the email address but allows the address to
 * be displayed on the page in a human readable form.
 */
function ParseEmail(node) {
	// replace the " dot " and " at " words with the appropriate symbols
	var email = node.firstChild.nodeValue.replace(/ dot /gi, ".").replace(/ at /i, "@");
	var link  = document.createElement("a");

	link.className = node.className;
	link.href = "mailto:" + email;

	// set the text depending on the title of the span
	link.appendChild(document.createTextNode((node.title != "") ? node.title : email));

	node.parentNode.replaceChild(link, node);
}


// set up and prepare for ParseEmail
function LoadHandler() {
	if(!document.getElementsByTagName) return;

	// converts email links
	var nodes = document.getElementsByTagName("span");
	var spans = [];

	// loop through the nodes and get *only* the spans with titles
	for(var i = 0; i < nodes.length; i++) {
		if(nodes[i].title != '') spans[spans.length] = nodes[i];
	}

	// a node list is "live" in that it updates it's contents as the document changes.
	// As ParseEmail replaces a span with a link an incremental loop won't work
	for(var i = 0; i < spans.length; i++) {
		ParseEmail(spans[i]);
	}
}