
// track outgoing links
if(typeof jQuery == 'function') { /* use jQuery if it exists because it is a more elegant solution */
  jQuery(function () {
    jQuery('a:not([href*="' + document.domain + '"])').click(function () {
      pageTracker._trackPageview('/outbound/' + jQuery(this).attr('href'));
    });
  });
}
else { /* use regular Javascript if jQuery does not exist */
  window.onload = function () {
    var links = document.getElementsByTagName('a');
    for (var x=0; x < links.length; x++) {
      links[x].onclick = function () {
        var mydomain = new RegExp(document.domain, 'i');
        if(!mydomain.test(this.getAttribute('href'))) {
          pageTracker._trackPageview('/outbound/' + this.getAttribute('href'));
        }
      };
    }
  };
}

// create a new window when the href tag has class="external"
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("class") == "external")
     anchor.target = "_blank";
   if (anchor.getAttribute("href") && anchor.getAttribute("class") == "externalplain")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

