// JavaScript Document
function HoverImgOf(filename) {
   var re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1_over.$2");
}
function NormalImgOf(filename) {
   var re = new RegExp("(.+)_over\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1.$2");
}
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) {
      category = "outlink";
    } else if (theLinkURL.indexOf("/video-") > -1) {
      category = "video";
    } else if (theLinkURL.indexOf(".pdf") > -1) {
      category = "document";
    } else if ($(this).parent().parent().attr("id") == "product_plus_tabs" || $(this).parent().parent().attr("id") == "exp_menu") {
      category = "tab_selected";
    } else {
      category = "pop_up";
    }
    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(){
   $(".imgHoverable").hover( 
      function() { $(this).attr("src", HoverImgOf($(this).attr("src")));  }, 
	  function() { $(this).attr("src", NormalImgOf($(this).attr("src"))); }
   );
    $(".bgHoverable").hover(
	  function() { $(this).css("background",HoverImgOf($(this).css("background-image")) + " no-repeat"); },
	  function() { $(this).css("background",NormalImgOf($(this).css("background-image")) + " no-repeat"); }
	);
    $(".parentBgHoverable").hover(
	  function() { $(this).parent().css("background",HoverImgOf($(this).parent().css("background-image")) + " no-repeat"); },
	  function() { $(this).parent().css("background",NormalImgOf($(this).parent().css("background-image")) + " no-repeat"); }
	);
    $(".childImgHoverable").hover(
      function() { $(this).children("img").attr("src", HoverImgOf($(this).children("img").attr("src"))); }, 
      function() { $(this).children("img").attr("src", NormalImgOf($(this).children("img").attr("src"))); }
    );
	$("#signup_text").focus(function() { 
	  if (this.defaultValue == this.value) { this.value = ""; } 
	});
    $("a[href^='http'], a[href$='.pdf'], #product_plus_tabs a, #exp_menu a, .iframe").click(GATrackEvent);
    $("body link, body style").appendTo("head");
});
