

$(document).ready(function(){
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	$.getScript(gaJsHost+"google-analytics.com/ga.js", function(){
		// This code needs to be changed to the code Google Analytics provides for your account
		try {
		var pageTracker = _gat._getTracker("UA-8165598-1"); //UA-8165598-1 - TUA's own code
		pageTracker._trackPageview();
		} catch(err) {}

		// The slashes are to ensure the period is in the url, the $ is to make sure it is the end of the url, the i is to make it case insensitive.
		filetypes = /\.doc$|\.xls$|\.exe$|\.zip$|\.pdf$|\.mp3$|\.psd$/i;
		$("a").live("click", function(){
			// Track mailto links
			if ($(this).attr("href").match(/^mailto\:/i)) {
				var url = $(this).attr("href").replace(/^mailto\:/i, "")
				pageTracker._trackPageview("/mailto/" + url)
				//alert("link: " + url)
			}
			// Track external links
			else if (location.host != this.host.replace(/\:80$/i, "")) {
				var url = $(this).attr("href").replace(/^http\:\/\/(www\.)*/i, "")
				pageTracker._trackPageview("/outgoing/" + url)
				//alert("link: " + url)
			}
			// Track downloads (links with a given extension)
			else if ($(this).attr("href").match(filetypes)) {
				// The URL needs to be changed for each site this is applied to.
				var host = location.host.replace(/\./, "\\.")
				var pattern = new RegExp('^(http\:\/\/)*(www\.)*('+host+')*\/','i')
				var url = $(this).attr("href").replace(pattern, "")
				pageTracker._trackPageview("/downloads/" + url)
				//alert("link: " + url)
			}
		});
	});
});

