/*
 * Webtracking with google analytics.
 */
var _gaq = _gaq || [];
(function() {
	_gaq.push([ '_setAccount', 'UA-25933681-2' ]);
	_gaq.push([ '_gat._anonymizeIp' ]);
	_gaq.push([ '_trackPageview' ]);

	if (location.host.match(/^localhost(:\d+)?$/)) {
		// no tracking while testing
		return;
	}

	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);
})();

$(function() {
	/*
	 * Deobfuscate email addresses.
	 */
	var characterMap = {
		at : '@',
		dot : '.',
		ddot : ':'
	};

	$('a.obfuscatedMail').each(function() {
		this.href = 'mailto:' + (this.innerHTML = this.innerHTML.replace(/\s*\[(.*?)\]\s*/g, function() {
			return characterMap[arguments[1]];
		}));
	});

	/*
	 * Track outbound links.
	 */
	$('a').click(function(event) {
		var href = $(this).attr("href");
		if (-1 === href.indexOf(':')) {
			// don't track local links
			return;
		}

		event.preventDefault();

		_gaq.push([ '_trackEvent', 'Outbound Link', 'click', href ]);

		setTimeout(function() {
			location.href = href;
		}, 100);
	});
});
