
function getFilenameExtension(psFilename) {
	var aFileParts = String(psFilename).split(/\./);
	var count = aFileParts.length;
	if (count > 1) {
		return aFileParts[count - 1];
	} else {
		return null;
	}
}

$(document).ready(function()
{
    // add onclick to all links (based on rules)
    var extensions = ['txt', 'pdf', 'doc', 'exe', 'dot', 'xls', 'ppt'];
    
    // first retrieve all links
    var oJQ = $('a');
    
    // Now we loop each link and find only those that have the correct extensions
	oJQ.each(function() {
		var link = $(this).attr('href');

		if (link != undefined)
		{
			bIsDownload = $.inArray(getFilenameExtension(link), extensions);
			if (bIsDownload > -1)
			{
				$(this).bind('click', function() {
					_gaq.push(['_trackEvent', 'Files', 'Download', $(this).attr('href')]);
				});
			}
		}
	});
});
