/**
 * Link Event Tracking
 * 
 * Uses jQuery to bind onclick logic to anchor tags.
 * Clicks on anchor tag links will trigger a GA event tracking beacon.
 * 
 * Sam Chen, Experian Hitwise sam.chen@au.experian.com
**/

$(function () {
// the time the page loaded (for time to click)
var loDate = new Date();

	// apply to all links except for ones that trigger animations/do not link elsewhere
	$('a').click(function () { 
		// var p1 = /^.*fancybox.*$/i; // regexp for elements that don't require pausing
		// the time the link was clicked
		var clkDate = new Date();
		var clkTime = Math.round((clkDate-loDate)/1000);
		var label = null;
		if($(this).has('img').length == 0) { // no img
			var txtalt = $(this).text();
			label = (txtalt.length ? txtalt : $(this).attr('href'));
		}
		else { // img exists
			var imgalt = $(this).children('img:first').attr('alt');
			if(imgalt != undefined) label = 'img:'+imgalt;
			else label = $(this).attr('href');
		}
		try { // track the event
			_gaq.push(['_trackEvent', 'clicked', $(this).parents('[id!=""]:first').get(0).id, label, clkTime]);
		}
		catch (err) {}
		// if(!(p1.test($(this).attr('id')))) { // pause for non-modal pop up elements for GA to fire
			var date = new Date();
			var curDate = null;
			do {
				curDate = new Date();
			} while(curDate-date < 100);
		// }
	});
})
