/* tracking pdf as events GA
   Note: GA code must be present on the page.
   Tracks all anchors with ".pdf" and applies target="_blank" if its missing - this is required to record events properly.
   If anchor has title specified it will record as "/123.pdf | Title attribute" 
     
*/

function callCustomGA(type,label) {
	if (type == 'pdf') {
	_gaq.push(['_trackEvent', 'Documents', 'Download', label]);
	}
	if (type == 'external') {
	_gaq.push(['_trackEvent', 'External Links', 'Click', label]);
	}
	return null;
}

$(document).ready(function() {

	$('a').each(function(index) {
		 var href = '';
 
 if ($(this).attr('href')) {
	href = $(this).attr('href');
 }

 var title = $(this).attr('title');
 var target = $(this).attr('target');

		
		if (href.indexOf('.pdf') >=0) {
					if ($(this).attr('target') != '_blank') $(this).attr('target','_blank');	
					if (title != '') href += (' | ' + title);
					
					$(this).click(function() {
						callCustomGA('pdf',href);
						
					});
					
		}
		
		if ((href.indexOf('http://') >=0) && (target=='_blank')) {

					$(this).click(function() {
						callCustomGA('external',href);
					});
					
		}
		

	});
	
})


