﻿function addOutboundLinkTracking()
{
	// could probably do it this way, but I'm not sure there's a performance gain
	// $('a[href^=http]:not([href*='terrehaute.com'],.external),area[href^=http]:not([href*='terrehaute.com'],.external)')
	
	// get all the links not already marked as external, but having an href that starts with http
	// remove those that link back to this site (contain "terrehaute.com")
	var links = 
		$('a,area')
			.filter('[href^=http]')
			.not('.external')
			.not("[href*='terrehaute.com']");
	
	// bind the trackPageview call to the click event of each link.
	// and mark them as external links.
	links
		.addClass('external')
		.click(function() {
			var tag = '/out/' + this.href.toLowerCase().replace(/^https?:\/\//i, '').replace(/\/$/g, '');
			pageTracker._trackPageview(tag);
		});
		
	// now process mailto: addresses
	links =
		$('a,area')
			.filter("[href^='mailto:']")
			.not('.external');
	
	links
		.addClass('external')
		.click(function() {
			var tag = '/out/mailto/' + this.href.toLowerCase().replace(/^mailto:/i, '');
			pageTracker._trackPageview(tag);
		});
}

$(addOutboundLinkTracking);