var ExternalLinkEventTracker = new Class
({
  Extends: EventTracker,
  
  trackEvents: function()
  {
    // get the base tag
    var baseHref = $('baseTag').href;
    
    // create a regular expression to match the href of page links
    var regex = new RegExp("^" + baseHref.escapeRegExp());
    
    // loop through all links on the page
    $$('a').each(function(el)
    {  
      // find all links that don't start with the base tag or http/https
      if(!el.href.match(regex) || !el.href.match(/^https?:\/\//g))
      {
        el.addEvent('click', function(clickEvent)
        {
          try
          {
            // stop the event to prevent the external link going out
            clickEvent.stop();
            
            // track the external click by firing the tracker event with the event data
            var eventData = {category:'Outbound Links', action: el.href};
            this.fireEventTracker(eventData);
            
            // now send the user to the href
            setTimeout('document.location = "' + el.href + '"', 100);
          } catch(err) {}
          
        }.pbind(this));
      }
    }.pbind(this))
  }
});

new ExternalLinkEventTracker();
