//Google Analytics

if ( typeof(UAcode) !== 'undefined' && UAcode !== null && UAcode !== ''){
	// Start Google Analytics External, Mailto, and Download Link Tracking
	document.onclick = function(event) {
		event = event || window.event;
		var target = event.target || event.srcElement,
		targetElement = target.tagName.toLowerCase();
		if (targetElement == "a") {
			var href = target.getAttribute("href"),
			urlHost = document.domain.replace(/^www\./i,""),
			urlPattern = "^(?:https?:)?\/\/(?:(?:www)\.)?" + urlHost + "\/?";
			if (href) {
				eventCheck(href,urlPattern);
			}
		}
		
		function eventCheck(href,urlPattern){
			if ((href.match(/^https?\:/i)) && (!href.match(urlPattern))){
				if (href.match(/^.*\.(avi|css|doc|docx|eps|exe|jpg|js|mov|mp3|pdf|png|ppt|pptx|py|rar|svg|txt|vsd|vxd|wma|wmv|xls|xlsx|zip)$/i)) {
					_gaq.push(['_trackEvent', 'Download', 'click', href]);
				} else {
					_gaq.push(['_trackEvent', 'External', 'click', href]);
				}
			} else if (href.match(/^mailto\:/i)) {
				_gaq.push(['_trackEvent', 'Email', 'click', href.substr(7)]);
			} else if (href.match(/^.*\.(avi|css|doc|docx|eps|exe|jpg|js|mov|mp3|pdf|png|ppt|pptx|py|rar|svg|txt|vsd|vxd|wma|wmv|xls|xlsx|zip)$/i)) {
				_gaq.push(['_trackEvent', 'Download', 'click', href]);
			}
		}
	};
	
	// Start Google Analytics Code
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', UAcode],['_trackPageview']);
	(function() {
			  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
			  })();
};
