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

var google_conversion_id_kx = 1067268106; 
var google_conversion_label_kx = "Eab0COiEmAEQivD0_AM";
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)$", "i");

jQuery(document).ready(function() {
  // a elements
  jQuery('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 (jQuery(this).is("a[href^=mailto:]")) {
        // Add the email action with the email address as the value
        pageTracker._trackEvent("Email", "Click", this.href.substring(7));

        // Add the adwords tracking
        var img = document.createElement('img');
        img.src = "http://www.googleadservices.com/pagead/conversion/" + google_conversion_id_kx + "/?label=" + google_conversion_label_kx + "&amp;guid=ON&amp;script=0";
        document.body.appendChild(img);
      }
      // 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
  jQuery('embed').click( function() {
    try {
      pageTracker._trackEvent("Embedded Object", "Click", this.src);
    }
    catch(e){}
  });
});

