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

var google_conversion_id = 1038886406; 
var google_conversion_label = "H27gCMDPtgEQhsyw7wM";
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");
var kxTrackEmbeddedClicks = false;

$(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));
				// Add the adwords tracking
				var img = document.createElement('img');
				img.src = "http://www.googleadservices.com/pagead/conversion/" + google_conversion_id + 
					"/?label=" + google_conversion_label + "&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
  if (kxTrackEmbeddedClicks) {  
    $('embed').click( function() {
      try {
        pageTracker._trackEvent("Embedded Object", "Click", this.src);
      }
      catch(e){}
    });
  }
});
