// Klixo Google Analytics Event Tracking
// Add event tracking for:
//  External links
//  File downloads
//  Mailto links
//  Embedded objects

var kxIsInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
var kxIsTrackedDownload = new RegExp("\\.(pdf|doc|txt|csv|xls|ppt|zip|wmv|wma|avi|swf|exe|mp3)$", "i");

$(document).ready(function() {
  // a elements
  $('a').click( function() {
    try {
      // See if it's one of the file types we want to track
      if (kxIsTrackedDownload.test(this.href)) {
        // Add a download action with the extension as the label and the
        // filename without the domain name as the value 
        pageTracker._trackEvent("Download", kxIsTrackedDownload.exec(this.href)[1], 
          this.href.replace(kxIsInternal, ""));
      }
      // Is it a mailto: link? (it is not internal)
      else if ($(this).is("a[href^=mailto:]")) {
        // Add the email action with the email address as the value
        pageTracker._trackEvent("Email", "Click", this.href.substring(7));
      }
      // It's an external link
      else if (!kxIsInternal.test(this.href)) {
        // Add the external link action with the href as the value
        pageTracker._trackEvent("External link", "Click", this.href);
      }    
    } catch(e){alert(e);}
  });
  
  // embed elements
  $('embed').click( function() {
    try {
      pageTracker._trackEvent("Embedded Object", "Click", this.src);
      alert("Object");
    }
    catch(e){}
  });
});
