// JavaScript Document
function getParentId (theElement) {
  if (theElement === undefined || theElement === null) {
    return "";
  } else {
    var theId;
    if (theElement.id !== undefined && theElement.id !== null && theElement.id !== "") {
      theId = theElement.id;
    } else {
      theId = getParentId (theElement.parentNode);
    }
    return theId;
  }
}
function getParentClass (theElement) {
  if (theElement === undefined || theElement === null) {
    return "";
  } else {
    var theClass;
    if (theElement.className !== undefined && theElement.className !== null && theElement.className !== "") {
      theClass = theElement.className;
    } else {
      theClass = getParentClass (theElement.parentNode);
    }
    return theClass;
  }
}
function GATrackEvent() {
  var category = "";
  var theLinkURL = $(this).attr('href');
  if (theLinkURL !== "" && theLinkURL !== null) {
    if (theLinkURL.indexOf("http") === 0 && theLinkURL.indexOf("chubbcollectorcar.com") === -1) {
      category = "outlink";
    } else if (theLinkURL.indexOf("/video-") > -1) {
      category = "video";
    } else if (theLinkURL.indexOf(".pdf") > -1) {
      category = "document";
    }
    if (category !== "") {
      var thisPage = location.href;
      var theId = getParentId(this);
      if (theId === "") {
        theId = getParentClass(this);
      }
      if (theId === null || theId === undefined || theId === "") {
        theId = "unknown element";
      }
      $(this).attr({ target: "_blank" });
      _gaq.push(['_trackEvent', category, theLinkURL, thisPage + " " + theId]);
    }
  }
}
$(document).ready(function(){
    $("a[href^='http'], a[href$='.pdf']").click(GATrackEvent);
});
