
$(document).ready(function() {
    // grab each link on the page
    $('a').each(function() {
    
        // extract the link address from the link
        var strLink = $(this).attr("href");
    
        // check if it's a link to one of our list
        if (IsLocalTrackableLink(strLink)) {
        
            // add an onclick method to it
            $(this).click(function() {
            
                // run the google page view function using old or asynchronous script
                if (!(typeof pageTracker === 'undefined')) {
                    pageTracker._trackPageview(strLink);
                    // Track how often old way of tracking is used
                    pageTracker._trackEvent('Synchronous GA', 'pdftracking.js', strLink);
                } else {                    
                    _gaq.push(['_trackPageview', strLink]);
                }
            });
        } 
    });
});

function IsLocalTrackableLink(linkUrl) {
    // check that a link is not null, is local, 
    // and contains our file extensions
    if (linkUrl != null && 
        linkUrl.indexOf("http://") < 0 && 
        linkUrl.match(/\.(?:doc|xls|pdf|zip|rar|exe|mp3|rtf)($|\&|\?)/)) {
        return true;
    }
    return false;
}

