﻿$(document).ready(function(){
	$.googletracklinks("UA-8458096-4");
	$.externallinks();
});

$.externallinks=function(){
	$('a[href^="http://"]').attr({  
		target: "_blank",
		title: function (arr) {
			if ($(this).attr("title").length>0)
			{
				$(this).attr("title",$(this).attr("title") + " (opens in a new window)");
			}
			else
			{
				$(this).attr("title","opens in a new window");
			}
        }
	});
}

$.googletracklinks=function(_uacct){
	// 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").each(function(){
		// Track mailto links
		if ($(this).attr("href").match(/^mailto\:/i)) {
			var url = "/mailto/" + $(this).attr("href").replace(/^mailto\:/i, "")
			$(this).click(function() {pageTracker._trackPageview(url);})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct);
			$(this).attr("title", $(this).attr("title") + " >>");
		}
		// Track external links
		else if (location.host != this.host.replace(/\:80$/i, "")) {
			var url = "/outgoing/" + $(this).attr("href").replace(/^http\:\/\/(www\.)*/i, "")
			$(this).click(function() {pageTracker._trackPageview(url);})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct);
			$(this).attr("title", $(this).attr("title") + " >>");
		}
		// 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 url_prefix = String(document.location).replace(/^(https?:\/\/[^:\/]+).*$/, "$1").replace(/^((site)?file:\/\/.+\/)[^\/]+$/, "$1").replace(/(\\.)/g, "\\$1");
			if (url_prefix="http://clients.byteart.com")
			{
				url_prefix+="/careyolsen2/";
			}
			//var url = '/downloads/' + $(this).attr("href").replace(/^(http\:\/\/)*(www\.)*(careyolsen\.com")*\//i, "");
			var url = '/downloads/' + $(this).attr("rel") + '/' + $(this).attr("title").replace(/ /g,"_");
			$(this).click(function() {pageTracker._trackPageview(url);})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct + " | " + url_prefix);
			$(this).attr("title", $(this).attr("title") + " >>");
		}
		else {
			// The URL needs to be changed for each site this is applied to.
			var url_prefix = String(document.location).replace(/^(https?:\/\/[^:\/]+).*$/, "$1").replace(/^((site)?file:\/\/.+\/)[^\/]+$/, "$1").replace(/(\\.)/g, "\\$1");
			if (url_prefix="http://www.crowntheclown.com")
			{
				url_prefix+="/careyolsen2/";
			}
			//var url = '/downloads/' + $(this).attr("href").replace(/^(http\:\/\/)*(www\.)*(careyolsen\.com")*\//i, "");
			var url = '/thickbox/' + $(this).attr("title").replace(/ /g,"_");
			$(this).click(function() {pageTracker._trackPageview(url);})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct + " | " + url_prefix);
			$(this).attr("title", $(this).attr("title") + " >>");
		}
	});
}