/**
 *  Omniture click tracking function
 *
 **/
function trackOmniClick(linkName, theObject, eventString, oVal) {
	if(typeof theObject === "undefined")
		var theObject = true;
	if(typeof eventString === "undefined")
		var eventString = "event61";
	if(typeof oVal === "undefined")
		var oVal = "o";

	var s=s_gi(s_account);
	s.linkTrackVars='events';
	s.linkTrackEvents=eventString;
	s.events=eventString;
	s.tl(theObject,oVal,linkName);
}
/**
 *  background-position rewiring for IE only
 *
 **/
  (function($) {
	jQuery.fn.getBackgroundPosition = function() {
	  var p = $(this).css('background-position');
	  if(typeof p == 'undefined')
	  	return $(this).css('background-position-x') + ' ' + $(this).css('background-position-y');
	  else
	  	return p;
	};
	jQuery.fn.setBackgroundPosition = function(val) {  
	  var q = $(this).css('background-position');
	  if (typeof q  == 'undefined') {
		  var r = val.split(' ');
		  var xpos = r[0];
		  var ypos = r[1];
		  $(this).css('background-position-x',xpos);
		  $(this).css('background-position-y',ypos);
	  } else {
		  $(this).css('background-position', val);
	  }
	};
  })(jQuery);
/* document ready for jquery */
$(function() {
/**
 *  search term/search box default watermark handling, 
 *  now "ensmartend" for i18n
 *
 **/
  if ($('#searchQuery').length) {
	/* what language, what string to use for search box, default En */
	var q, oWmDefault = {
		strings: {
			Ja_JP: "検索",
			Es_ES: "search",
			Nl_NL: "search",
			De_DE: "search",
			Fr_FR: "search",
			Sv_SE: "search",
			En:    "search"
		},
		getLangLoc: function() {
			var a,b,c=document.location.pathname;
			b=c.split("/");
			a=b[1].length;
			b=(a==5)?b[1]:'';
			return b;
		},
		getString: function() {
			var z=this.strings.En, c=this.getLangLoc();
			if (c.length) {
				if (typeof this.strings[c] !== "undefined" ) {
					z = this.strings[c];
				}
			}
			return z;
		}
	};
	q = ( typeof searchTerm !== "undefined" ) ? searchTerm : oWmDefault.getString();
	$('#searchQuery').watermark(q, {useNative: false});
  }
/**
 *  locale selector arrow hover effect 
 *
 **/
  if ($('ul#dropz').length) {
   /* locale selector dropdown arrow toggle if ul#dropz exists */
   $('ul#dropz').hover(
     function() { $('ul#dropz a').setBackgroundPosition('left -5px'); },
     function() { $('ul#dropz a').setBackgroundPosition('left 6px'); }
   );
  }
/**
 *  tabs hover effects 
 *
 **/



  if ( $('div#global_tabs').length ) {
	/* hover state map */
	var otabs = {
		"1" : {active:"0px 0px",    hover:"-356px 0px",    inactive:"-202px 0px"   },
		"2" : {active:"0px -36px",  hover:"-356px -36px",  inactive:"-202px -36px" },
		"3" : {active:"0px -72px",  hover:"-356px -72px",  inactive:"-202px -72px" },
		"4" : {active:"0px -108px", hover:"-356px -108px", inactive:"-202px -108px"},
		"5" : {active:"0px -144px", hover:"-356px -144px", inactive:"-202px -144px"}
	};	
	$("div#global_tabs div").each(function(ix,me)
	{
		var a,i = ix+1;
		if ($("div#global_tabs a.active").length)
		{
			a = ($("div#global_tabs a.active").parent().attr("class") == $(me).attr("class"));
		}
		else
		{
			var validTest = RegExp(/^\D*(\d*)\D*(\d*)\D*$/);
			var testValue = validTest.exec($(me).getBackgroundPosition())
			var testValue2 = validTest.exec(otabs[i].active)
			a = (testValue[1] == testValue2[1] && testValue[2] == testValue2[2]);
		}

		if (a) {
			$(me).css({width:"202px",margin:"0 0 0 -4px"}).setBackgroundPosition(otabs[i].active);
		} else {
			$(me).hover(
				function() { $(me).setBackgroundPosition(otabs[i].hover); },
				function() { $(me).setBackgroundPosition(otabs[i].inactive); }
			);
		} 

	});
  }
});
function getQueryStringParameter(paramName)
{
	regEx = / /;
	regEx.compile("[?&]" + paramName + "=([^&]*)");
	if(result = regEx.exec(location.search))
		return result[1];
	else
		return null;
}
function createFormFields(formName,queryStringName,fieldName)
{
	if(!(paramValue = getQueryStringParameter(queryStringName)))
		return false;
	else
		$("form[name='" + formName + "']").prepend("<input type='hidden' name='" + fieldName + "' value='" + paramValue + "'/>");
	return true;
}
function prepEloquaHiddenFields(formName)
{
	createFormFields(formName,"g","LightboxSearchEngine");
	createFormFields(formName,"r","LightboxSearchRegion");
	createFormFields(formName,"k","LightboxSearchKeyword");
}

