$(document).ready(function() {
	$("span.email-replacement").each(function() {
		var index = $(this).attr("rel");

		$(this).replaceWith( decodeEmail( decodeEmailSource[index]['coded'], decodeEmailSource[index]['key'], decodeEmailSource[index]['alternateText'], decodeEmailSource[index]['linkClass']) );
	});
});


// Email obfuscator script 2.1 by Tim Williams, University of Arizona
// Random encryption key feature by Andrew Moulden, Site Engineering Ltd
// This code is freeware provided these four comment lines remain intact
// A wizard to generate this code is at http://www.jottings.com/obfuscator/
 
//Modified by Justin
function decodeEmail(coded, key, alternateText, linkClass) {
	var shift = coded.length;
	var link = '';

	var email = '';

	for (i=0; i<coded.length; i++) {
		if (key.indexOf(coded.charAt(i))==-1) {
			ltr = coded.charAt(i);
			link += (ltr);
		} else {
			ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length;;
			link += (key.charAt(ltr));
		}
	}
	if (alternateText) {
		if (linkClass) {
			email = "<a href='mailto:"+link+"' class='" + linkClass + "'><span>" + alternateText + "</span></a>";
		} else {
			email = "<a href='mailto:"+link+"'><span>" + alternateText + "</span></a>";
		}
	} else {
		if (linkClass) {
			email = "<a href='mailto:"+link+"' class='" + linkClass + "'><span>" + link + "</span></a>";
		} else {
			email = "<a href='mailto:"+link+"'><span>" + link + "</span></a>";
		}
	}

	return email;
}

var decodeEmailSource = [
	{
		// matts@mattsphotoworld.com
		coded: "lXOOu@lXOOuUqzOzHz9sc.1zl",
		key: "NtoKRdjrTxYlL2vUaHgiPJqf3FOzb7c69QCysS0E5X8eBnVGm4DMpZw1IAWhku",
		alternateText: "",
		linkClass: "email"
	}
]
