$(document).ready(function(){
  $(document.body).click(function(event) {
      $(event.target).parents("a:first,area:first").andSelf().filter("a,area").each(function() {

        // list of extensions to track.
        var trackDownloadExtensions = "7z|aac|arc|arj|asf|asx|avi|bin|csv|doc?x|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt?x|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls?x|xml|z|zip";
        
        var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
        var isDownload = new RegExp("\\.(" + trackDownloadExtensions + ")$", "i");

        // Is the clicked URL internal?
        if (isInternal.test(this.href)) {
          // download (file)
          if (isDownload.test(this.href)) {
            var extension = isDownload.exec(this.href);
            _gaq.push(["_trackPageview", '/downloads/' + extension[1].toUpperCase() + this.href.replace(isInternal, '')]);
            _gaq.push(["b._trackPageview", '/downloads/' + extension[1].toUpperCase() + this.href.replace(isInternal, '')]);
            //_tag.dcsDownload(event);
          }
        }
        else {
          // mailto
          if ($(this).attr("href").match(/^mailto:/)) {
            _gaq.push(["_trackPageview", '/mailto/' + this.href.substring(7)]);
            _gaq.push(["b._trackPageview", '/mailto/' + this.href.substring(7)]);
          }
          // external
          else if (this.href) {
              _gaq.push(["_trackPageview", '/external/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
              _gaq.push(["b._trackPageview", '/external/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
              //_tag.dcsOffsite(event);
          }
        }
      });
    });
 });
