$(document).ready(function() {
	var processTextNodes_r = function(elem, callback) {
		for (var i = 0; i < elem.childNodes.length; i++) {
			switch (elem.childNodes[i].nodeType) {
				case 1:
					processTextNodes_r(elem.childNodes[i], callback);
					break;
					
				case 3:
					callback.call(elem.childNodes[i]);
					break;
			}
		}
	};
	
	var innerBody = document.getElementById("innerBody");
	if (innerBody) {
		processTextNodes_r(innerBody, function() {
			var obfuscated = this.nodeValue.match(/[A-Za-z0-9\.]+\(at\)[A-Za-z0-9\-\.]*[A-Za-z0-9]/);
			if (obfuscated) {
				//alert("Obfuscated email address(es): " + obfuscated);
				
				for (var i = 0; i < obfuscated.length; i++) {
					var obIndex = this.nodeValue.indexOf(obfuscated[i]);
					
					// Break the obfuscated text into its own text node
					var obNode = this.splitText(obIndex);
					obNode.splitText(obfuscated[i].length);
					
					// Grab the two parts of the obfuscated email
					var atPos = obNode.nodeValue.indexOf("(at)");
					var mailbox = obNode.nodeValue.substr(0, atPos);
					var domain = obNode.nodeValue.substr(atPos + "(at)".length);
					
					// Create an anchor with the appropriate link
					var elemLink = document.createElement("a");
					elemLink.href = "mailto:" + mailbox + "@" + domain;
					elemLink.appendChild(document.createTextNode(mailbox + "@" + domain));
					
					// Replace the obfuscated node with the link
					var textNodeParent = this.parentNode;
					textNodeParent.insertBefore(elemLink, obNode);
					textNodeParent.removeChild(obNode);
				}
			}
		});
	}
});
