/*------------------------------------------------------------------+
 | Utilizes event tracking in Google Analytics to track  |
 | clicks on outbound, document,  and email links.           |
 | Requires jQuery                                                             |
 +-------------------------------------------------------------------*/

jQuery(function () {

	var _trackClickEventWithGA = function (category, label) {
		if (typeof (_gaq) != 'undefined')
			_gaq.push(['_trackEvent', category, "Click", label]);
	};

	jQuery('a').click(function () {
		var $a = jQuery(this);
		var href = $a.attr("href");
		if (!href) return;

		//links going to outside sites
		if (href.match(/^http/i) && !href.match(document.domain)) {
			_trackClickEventWithGA("Outgoing", href);
		}

		//direct links to files
		if (href.match(/\.(avi|css|doc|docx|exe|gif|js|jpg|mov|mp3|pdf|png|ppt|pptx|rar|txt|vsd|vxd|wma|wmv|xls|xlsx|zip)$/i)) {
			_trackClickEventWithGA("Downloads", href);
		}

		//email links
		if (href.match(/^mailto:/i)) {
			_trackClickEventWithGA("Emails", href);
		}
	});
});
