﻿jQuery(document).ready(function(){
	var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|flv)$/i;
	jQuery('a').each(function(){
		if (jQuery(this).attr('href') != undefined){
			var href = jQuery(this).attr('href');
			if ((href.match(/^https?\:/i)) && (!href.match(document.domain))){
				jQuery(this).click(function() {
					var extLink = href.replace(/^https?\:\/\//i, '');
					pageTracker._trackEvent('ClickEvent External', 'Click', extLink);
				});
			}
			else if (href.match(/^mailto\:/i)){
				jQuery(this).click(function() {
					var mailLink = href.replace(/^mailto\:/i, '');
					pageTracker._trackEvent('ClickEvent Email', 'Click', mailLink);
				});
			}
			else if (href.match(filetypes)){
				jQuery(this).click(function() {
					var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
					var filePath = href.replace(/^https?\:\/\/(www.)mydomain\.com\//i, '');
					pageTracker._trackEvent('ClickEvent Download', 'Click - ' + extension, filePath);
				});
			};
		};
	});
});
