// Google Analytics - track downloads and external links
$(function() {
  $('a').click(function() {
    if ($(this).get(0).protocol == 'mailto:') {
      pageTracker._trackPageview('/mailto/' + $(this).attr('href').substring(7))
    } else if ($(this).get(0).hostname == location.host) {
      var path = $(this).get(0).pathname + $(this).get(0).search
      var isDoc = path.match(/\.(?:doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)($|\&|\?)/)
      var isBetstonePDF = path.match(/^downloads\/download\/[0-9]+/)
      if (isDoc) {
        trackPageView($(this).get(0), 'downloads')
      } else if (isBetstonePDF) {
        var parSheet = '/downloads/par-sheets/' + $(this).parent().prev('td').text().replace(' ', '') + '.pdf'
        pageTracker._trackPageview(parSheet)
      }
    } else {
      trackPageView($(this).get(0), 'external')
    }
  });
});
trackPageView = function(link, tag) {
  var page = (link.pathname.charAt(0) == "/") ? link.pathname : "/" + link.pathname
  if (link.search && link.pathname.indexOf(link.search) == -1) page += link.search
  if (link.hostname != location.host) page = '/' + tag + '/' + link.hostname + page
  pageTracker._trackPageview(page)
}