
$(document).ready(function(){
	
	// de-obfuscate SPAM-proof email addresses
		function deobfuscate(x){
			return x.replace("--/at/--","@");
		}
		$("a").each(function (i){
			var h = this.href;
			if (h.indexOf("mailto")==0) {
				var t = deobfuscate($(this).html());
				this.href = deobfuscate(h);
				$(this).html(t);
			}
		});
		
	// handle external links
		// (add https and don't include urls that start with site domain
		var pre = "/LINK/";				// prefix to add to URL for GA tracking code
		$('a[@href^="http://"]')
			.addClass('external')			// add CSS class for styling
			.attr('target', '_self')		// open in popup window
			.click(function(){				// GA tracking code
				var href = $(this).attr("href");
				href = href.substr(7,9999);	// trim off http://
				var i = href.indexOf("www.");	// trim off www.
				if (i===0){
					href = href.substr(4,9999);
				}
				href = encodeURI(href);		// encode URL
				$.log(pre + href);			// log href to console
				//pageTracker._trackPageview(pre + href)	// GA tracker code
				//return false;				// cancel link action
			})
		;
});

