/****************************************************************************************

Copyright (c) 2009 Ethicon Endo-Surgery, Inc.(EES).

This software is the confidential and proprietary information of EES. ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement you entered into with EES.

DOC			Site Scripts
VERSION 	1.1
AUTHOR		Doug Scamahorn
EMAIL		dscamahorn@fusionalliance.com

DATE       	NAME           	DESCRIPTON
10/07/2008 	Doug Scamahorn 	Initial creation.
8/25/2009	Doug Scamahorn	Analytics setup.
09/21/2009	Doug Scamahorn	Update to dialog function, addition of image rollover script, feature detection for Opera, and preloading plugin, created tooltip functionality
04/13/2010	Doug Scamahorn	Added pophelper function

****************************************************************************************/

/* GOOGLE ANALYTICS FUNCTIONS 
------------------------------------------------------------------------------------ */

/*var gaJsHost;
if (document.location.protocol == "https:") {
	gaJsHost = "https://ssl."
} else {
	gaJsHost = "http://www."
}
//var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl.google-analytics.com/ga.js" : "http://www.google-analytics.com/ga.js");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
function startAnalytics() {
	var pageTracker = _gat._getTracker("UA-4836125-2");
	pageTracker._initData();
	pageTracker._trackPageview();
}

if (window.addEventListener) {
	window.addEventListener('load', startAnalytics, false);
}
else if (window.attachEvent) {
	window.attachEvent('onload', startAnalytics);
}*/

/* =LEGACY REFINE SEARCH (consider revising to utilize jQuery)
---------------------------------------------------------------------------------------*/

	//Extend the DOM
	function getElementsByClassName(name) {
		var results = new Array;
		var elems = document.getElementsByTagName("*");
		for (var i = 0; i < elems.length; i++) {
			if (elems[i].className.indexOf(name) != -1) {
				results[results.length] = elems[i];
			}
		}
		return results;
	}
	
	function getNextElement(node) {
	  if(node.nodeType == 1){
	  	return node;
	  }
	  if(node.nextSibling) {
	 	 return getNextElement(node.nextSibling)
	  }
	  return null;
	}
	
	
	function refineSearchHover(){
		if(!document.getElementById('aRefineSearch')){return;}
	
		if (!document.getElementsByClassName) {
			document.getElementsByClassName = function (cn) { 
				var rx = new RegExp("(?:^|\\s)" + cn+ "(?:$|\\s)");
				var allT = document.getElementsByTagName("*"), allCN = [],ac="", i = 0, a;
					while (a = allT[i=i+1]) {
					  ac=a.className;
					  if ( ac && ac.indexOf(cn) !==-1) {
						if(ac===cn){ allCN[allCN.length] = a; continue;   }
						rx.test(ac) ? (allCN[allCN.length] = a) : 0;
					  }
					}
				return allCN;
			}
		}
	
		var refineSearchLinks=getElementsByClassName('c_locatorFlyoutRefineSearchLink');
		
		for (var i = 0; i < refineSearchLinks.length; i++) {
	  		
			refineSearchLinks[i].onmouseover = function(){
				var refineSearchPanel=getNextElement(this.nextSibling);
				addClass(refineSearchPanel,'rsHover');
				this.onmouseover = function(){
					addClass(refineSearchPanel,'rsHover');
				}
				refineSearchPanel.onmouseover = function(){
					addClass(this,'rsHover');
				}
				refineSearchPanel.onmouseout = function eventBurst(e) {
					if (!e) var e = window.event;
					var tg = (window.event) ? e.srcElement : e.target;
					if (tg.nodeName != 'DIV') return;
					var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
					while (reltg != tg && reltg.nodeName != 'BODY')
						reltg= reltg.parentNode
					if (reltg== tg) return;
					// Mouseout took place when mouse actually left layer
					// Handle event
					removeClass(this,'rsHover');
				}
			}
		}
	}
	
	function mouseOutEventHandler(e) {
	     e = e || window.event;
	     var target = e.srcElement || e.target;
	     if (target != this) return;
	
	     var related = e.relatedTarget || e.toElement;
	     while (related != this && related.nodeName != 'BODY')
	          related = related.parentNode;
	     if (related == this) return;
	   
	     // the rest of the function
	}
	
	//Add a class to an element
	
	function hasClass(ele,cls) {
		return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
	} 
	
	function addClass(ele,cls) {
		if (!this.hasClass(ele,cls)) ele.className += " "+cls;
	}
	
	function removeClass(ele,cls) {
		if (hasClass(ele,cls)) {
			var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
			ele.className=ele.className.replace(reg,' ');
		}
	}

/* =EXTEND JQUERY / JQUERY PLUGINS
---------------------------------------------------------------------------------------*/

	//Slide / Fade Effect
	jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
	};
	//Preload Images
	jQuery.preloadImages = function() {
		for(var i = 0; i<arguments.length; i++) {
			jQuery("<img/>").attr("src", arguments[i]);
		}
	}

/* =STANDARD FUNCTIONS
---------------------------------------------------------------------------------------*/
	
	//http://yura.thinkweb2.com/cft/ - COMPUTED_STYLE_RETURNS_VALUES_FOR_STATICLY_POSITIONED_ELEMENTS
	function featureDetectionOpera () {
		var view = document.defaultView; 
		if (view && view.getComputedStyle) {
			var docEl = document.documentElement; 
			var position = null; 
			var style = view.getComputedStyle(docEl, null);
			if (style.position !== "static") {
				position = style.position;
				docEl.style.position = "";
			}
			var result = view.getComputedStyle(docEl, null).left !== "auto";
			if (position !== null) {
				docEl.style.position = position;
			}
			return result;
		}
		return null;
	}
	//Slice a link helper function
	function fncSliceLink(pLink){ 
	//Get the path, file name, and file type of the link supplied, scheme://host.domain:port/path/filename.type?field1=value1&field2=value2
		//Get the link's href
		var vLinkAddress = pLink;
		//See if the link contains a query string
		if (vLinkAddress.indexOf("?")>1) {
			//If the link contains a query string, store the query string for later use
			var vQueryString = vLinkAddress.substring(vLinkAddress.indexOf("?"));
			//If the link contains a query string, then remove the query string for further processing
			vLinkAddress=vLinkAddress.substring(0,vLinkAddress.indexOf("?"));
		} else {
			vQueryString="";
		}
		//Get the number of characters from the beginging of the URI to the end of the scheme://
		var vSchemeIndex = vLinkAddress.indexOf("//")+2; //2 is the number of characters in the //
		//Get the string after the //
		var vDomianPlusPathString = vLinkAddress.substring(vSchemeIndex);
		//Get the ending point of the protocol by looking for the next forward slash
		var vIndexOfNextForwardSlash = vDomianPlusPathString.indexOf("/");
		//Get the string after the forward slash which is the path
		var vPathString = vDomianPlusPathString.substring(vIndexOfNextForwardSlash);
		//Get the protocol by getting the string from the 0 index character to the next forward slash
		var vDomainString = vDomianPlusPathString.substring(0,vIndexOfNextForwardSlash)
		//Find the last occurance of a forward slash
		var vIndexOfLastForwardSlash = vPathString.lastIndexOf("/")+1;//1 is the number of characters in the /
		//Get the filename and type string
		var vFileNameAndTypeString = vPathString.substring(vIndexOfLastForwardSlash);
		//Find the last dot in the filename and type string
		var vIndexOfLastDot = vFileNameAndTypeString.lastIndexOf(".");//1 is the number of characters in the .
		//See if the page is a framework component
		if (vIndexOfLastDot > 0){
			//Get the file name
			var vFileNameString = vFileNameAndTypeString.substring(0,vIndexOfLastDot);
			//Get the file type
			var vFileTypeString = vFileNameAndTypeString.substring(vIndexOfLastDot);
		} else {
			//Get the file name
			var vFileNameString = vFileNameAndTypeString;
			//Get the file type
			var vFileTypeString = "";
		}		
		//Return an array of the values from the function for use in other scripts
		var vReturnValuesArray = new Array(vDomainString,vPathString,vFileNameString,vFileTypeString,vQueryString);
		return vReturnValuesArray;
	}

/* =DOM MANIPULATION
---------------------------------------------------------------------------------------*/

	//Ensure REALIZE descriptors do not wrap
	function fixRealizeWrap(){
		$('*:contains("REALIZE mySUCCESS<sup class="pt_doc_sscript">&reg;</sup>")').each(function(){
		if($(this).children().length < 1) 
          $(this).html( 
               $(this).text().replace(
                    /"I am a simple string"/
                    ,'<span class="realizebrandwrap">"REALIZE mySUCCESS<sup class="pt_doc_sscript">&reg;</sup>"</span>' 
               )  
           ) 
		});
	}
	
	//Fixes codi removal of dom elements within an anchor
	function fixShareStoryCTA(){
		$("p.sharestorycta a").empty().append("<img src='/images/interface/btnShareStory.gif'>");
	}
	
	//Style the Primary Nav
	function modifyDropDownMenus() {
		$("#menu_top_dyna ul:first>li:first").attr("id","navFirst");
		$("#menu_top_dyna ul:first>li:last").attr("id","navLast");
		$("#menu_top_dyna ul li ul li a").each(function(){
			$(this).append("<span>&nbsp;&nbsp;&nbsp;</span>");
		});
		var getStartedOrderedList = $("#menu_top_dyna ul:first>li:eq(1)").find("ul:first");
		var getStartedListContents = $(getStartedOrderedList).html();
		$(getStartedOrderedList).replaceWith('<ol>' + getStartedListContents + '</ol>');
		$("#menu_top_dyna ul:first>li:eq(2)>ul:first").addClass("mega");
		$("#menu_top_dyna ul:first>li#navFirst.navPrimaryActive").css("background-position","0px -402px");
		$("#menu_top_dyna ul:first>li#navLast.navPrimaryActive").css("background-position","right -346px");
	}
	//Add Mega Menu
	function addMegaMenu(){
		if ($.cookie("interactiveComponents") != "disabled") {
			$.ajax({
				url: "/inc-menu-surgical-procedures.htm",
				success: function(html){
					var menu = html;
					$(".mega li").each(function(i){
						$(this).append($(menu).find("ul:eq("+i+")"));
					});
				}
			});
		}
	}
	//Move gutter contents
	function moveGutterContents() {
		$(".navSecondaryContainer").append($("td.pt_doc_gutterIncludeHtml").html());
	}
	//Wrap linked superscript symbols such as footnotes with a sup tag in order to overcome CODI nested tag issues
	function addMarkupLinkedSuperScriptSymbols() {
		$("a.pt_doc_sscript").wrap("<sup class='pt_doc_sscript'></sup>");
	}
	//Add markup to headers for IE
	function headerStyling(){
		/*$("td.pt_doc_section").each(function(){
			$(this).find("div.pt_doc_sectionTitle + span.pt_doc_sectionText > div.pageSection > :header:first-child").css("margin-top","18px");
			$(this).find("div.pt_doc_sectionTitle + span.pt_doc_sectionText > :header:first-child").css("margin-top","18px");
		});
		$("h2+h3, h3+h4").filter("div.landingMenuInternal+h2+h3").css("margin-top","18px");*/
	$(".accordiancontent h2").addClass('sIFR-ignore');
	$(".accordiancontent h3").addClass('sIFR-ignore');
	}
	//Setup a hover event for img buttons
	function hoverImageButtons() {
		$("img[src*='interface/btn']").each(function(i){
			var vButtonSourcePath = $(this).attr("src").slice(0,-4);
			var vButtonSourceType = $(this).attr("src").slice(-4);
			//Preload images
			$.preloadImages(vButtonSourcePath + "Hover" + vButtonSourceType);
			$(this).hover(
				function () {
					$(this).attr({src: vButtonSourcePath + "Hover" + vButtonSourceType});
				},
				function () {
					$(this).attr({src: vButtonSourcePath+vButtonSourceType});
				}
			);
		});
	}
	//Setup a hover event for image rollovers
	function hoverImages() {
		$("img.hoverImage").each(function(i){
			var vImageSourcePath = $(this).attr("src").slice(0,-4);
			var vImageSourceType = $(this).attr("src").slice(-4);
			//Preload images
			$.preloadImages(vImageSourcePath + "Hover" + vImageSourceType);
			$(this).hover(
				function () {
					$(this).attr({src: vImageSourcePath + "Hover" + vImageSourceType});
				},
				function () {
					$(this).attr({src: vImageSourcePath+vImageSourceType});
				}
			);
		});
	}
	//Strip Tables
	function stripeTables() {
		//Strip Grids
		$("table.datagrid").each(function(i){
			$(this).find("tr").each(function(i){
				if (!(i % 2)) {
					$(this).addClass("oddrow");
				}
				$(this).children(':last-child').css("border-right","none");
			});
		});
		//Accordion Grids
		$("dl.accordionlist dd.grid table.datagrid").each(function(i){
			if (($(this).find("tr").length % 2) && $(this).next().length == 0) {
				$(this).closest("dl.accordionlist dd.grid div.inner").css("background","url(/images/interface/bgAccordionContentGrid.gif) no-repeat right bottom");
				$(this).closest("dl.accordionlist dd.grid").css("background","url(/images/interface/bgAccordionContentGrid.gif) no-repeat left bottom");
			}
		});
	}

	function enhanceTouts() {
		$('.contenttout').wrapInner('<div class="contenttout_inner wrap"></div>');
	}
	
/* =FORMS
---------------------------------------------------------------------------------------*/

	//Remove the br tag from the form disclaimer div
	function removeMarkupFormDisclaimer(){
		$("div.cc_Disclaimer br").remove();
	}
	
	
	
	
	
	//Reorganize and style Loginservice pages
	function reorganizeStyleLogin(){
		var vFilePath=fncSliceLink(location.href)[1];
		if (vFilePath == "/dtcf/components/share-your-story" || "/dtcf/components/share-your-story/result") {
			//Remove div
			$("div.cc_Disclaimer").remove();
		}
	}
	
	

	
	//Reorganize and style checkbox instruction text
	function reorganizeCheckboxInstructionText(){
		var source = $("td[class$='cc_formFieldLabel']>span.cc_formFieldInstruction");
		$(source).each(function (){
			var target=$(this).parent().next();
			$(target).addClass("cc_formFieldInput");
			$(this).appendTo(target);
		});
	}
	//Change the background style of radio and checkbox inputs and remove the check all script and onclick event from radio buttons
	function styleRadioCheckboxInputs(){
		$("input[type='radio']").addClass("checkboxRadioInputs");
		$("input[type='checkbox']").addClass("checkboxRadioInputs");
		$("input[type='checkbox'][onclick]").removeAttr("onclick");
		$("div.cc_formFieldCheckboxGroup>script").remove();			
	}
	//Wrap the Communication Preferences radio group in divs
	function addMarkupCommunicationPref(){
		var target = $("input[value='active']").parent().prev();
		$("input[value='active']").parent().contents().wrapAll("<div class='communicationPref'></div>");
		$("input[value='active']").parent().find("img.cc_formFieldRequired").appendTo(target);
	}
	//Wrap the checkbox group copy in divs
	function addMarkupCheckboxGroup(){
		$("div.cc_formFieldCheckboxGroup td").each(function(){
			$(this).contents().wrapAll("<div></div>");
		});
	}
	//Show/hide open text field functionality for form elements with an "other" option
	function showHideOtherFields(){
		if ($.cookie("interactiveComponents") != "disabled") {
			//Hide all input fields with a name that ends with other
			$("input[name$='other']").hide().css("border","solid 1px #5cc151");
			//Hide all the instruction text for the "other" input fields
			$("input[name$='other']").next().hide().css("color","#5cc151");
			//Hide all the error text for the "other" input fields
			$("input[name$='other']").parent().parent().next().find("td.cc_formError").hide();
			//Hide the next table row
			$("input[name$='other']").parent().parent().next().next().hide();
			//For each "other" input field
			$("input[name$='other']").each(function (i) {
				//Store the name of the select element
				var parentElement = $(this).parent().parent().prev().prev().prev().find("select").attr("name");
				//Assign the change event
				$("select[name='"+parentElement+"']").bind("change keydown keyup", function () {
					var $selected = $(this).find("option:selected");
					var inputName = $selected.parent().attr("name")+"_other";
					//Store the value of the selection
					var selectionValue = $selected.text();
					//If the selectionValue is other
					if (selectionValue=="Other"){
						//Show the next table row
						$("input[name$='"+inputName+"']").parent().parent().next().next().slideDown();
						//Show the input field
						$("input[name$='"+inputName+"']").slideDown();
						//Show the instruction text
						$("input[name$='"+inputName+"']").next().slideDown();
						//Show the error text
						$("input[name$='"+inputName+"']").parent().parent().next().find("td.cc_formError").slideDown();
					} else {
						//Hide the error text
						$("input[name$='"+inputName+"']").parent().parent().next().find("td.cc_formError").slideUp();
						//Hide the instruction text
						$("input[name$='"+inputName+"']").next().slideUp();
						//Hide the input field
						$("input[name$='"+inputName+"']").slideUp();
  						//Hide the next table row
						$("input[name$='"+inputName+"']").parent().parent().next().next().slideUp();
					}
				}).change();
			});
			var other_role_checkbox = $("input:checkbox[name='other_role']");
			$(other_role_checkbox).click(function() {
				if (this.checked) {
					//Show the error text
					$(this).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().next().find("td.cc_formError").slideDown();
					//Show the next table row
					$(this).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().next().next().slideDown();
					//Show the input field
					$(this).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().find("input[name$='other']").slideDown();
					//Show the instruction text
					$(this).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().find("input[name$='other']").next().slideDown();
				} else {
					//Hide the error text
					$(this).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().next().find("td.cc_formError").slideUp();
					//Hide the instruction text
					$(this).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().find("input[name$='other']").next().slideUp();
					//Hide the input field
					$(this).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().find("input[name$='other']").slideUp();
					//Hide the next table row
					$(this).parent().parent().parent().parent().parent().parent().parent().next().next().next().next().next().slideUp();
				}
			});
			//If the Other checkbox is checked show the Other field
			if ($(other_role_checkbox).is(":checked")) {
					//Show the error text
					$(other_role_checkbox).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().next().find("td.cc_formError").slideDown();
					//Show the next table row
					$(other_role_checkbox).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().next().next().slideDown();
					//Show the input field
					$(other_role_checkbox).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().find("input[name$='other']").slideDown();
					//Show the instruction text
					$(other_role_checkbox).parent().parent().parent().parent().parent().parent().parent().parent().next().next().next().find("input[name$='other']").next().slideDown();
			}
		}
	}
	//Setup a hover event for the Mini Search Component button
	function hoverMiniSearchGoButton() {
		if ( $("input.c_searchgMiniSubmitImage").length > 0 ) {
			var vButtonSourcePath = $("input.c_searchgMiniSubmitImage").attr("src").slice(0,-4);
			var vButtonSourceType = $("input.c_searchgMiniSubmitImage").attr("src").slice(-4);
			//Preload images
			$.preloadImages(vButtonSourcePath + "Hover" + vButtonSourceType);
			$("input.c_searchgMiniSubmitImage").hover(
				function () {
					$(this).attr({src: vButtonSourcePath + "Hover" + vButtonSourceType});
				},
				function () {
					$(this).attr({src: vButtonSourcePath+vButtonSourceType});
				}
			);
		}
	}
	//Enhance the Mini Search Component's input field with markup for advanced styling and it's value
	function enhanceMiniSearchField() {
		if ( $(".c_searchgMiniFieldInput").length > 0 ) {
			//Wrap it in a div
			//$(".c_searchgMiniFieldInput").wrap("<div></div>");
			//Get/Set the field values
			$(".c_searchgMiniFieldInput").val("Site Search");
			$(".c_searchgMiniFieldInput").focus(function () {
				if($(this).val() == "Site Search"){
					$(this).val("");
				}
			});
			$(".c_searchgMiniFieldInput").blur(function () {
				if($(this).val() == ""){
					$(this).val("Site Search");
				}
			});
		}
	}
	//Setup a hover event for the submit button on forms
	function hoverFormInputButtons() {
		$("input.cc_formSubmitImage").each(function(i){
			var vButtonSourcePath = $(this).attr("src").slice(0,-4);
			var vButtonSourceType = $(this).attr("src").slice(-4);
			$(this).hover(
				function () {
					$(this).attr({src: vButtonSourcePath + "Hover" + vButtonSourceType});
				},
				function () {
					$(this).attr({src: vButtonSourcePath+vButtonSourceType});
				}
			);
		});
	}
	
/* =POP HELP
---------------------------------------------------------------------------------------*/

	function pophelper(){
		$(".pophelp").each(function(){
			$(this).find("span.hover").hide();
			
			$(this).find("span.default").mouseenter(
				function () {		
						
						$(this).closest(".pophelp").animate({
							width: '285'
						}, 200, function() {
							$(this).closest(".pophelp").find("span.default").fadeOut(10,function(){
								$(this).next().fadeIn(500);
							});
						});
						
					}
			);
			
			$(this).find("span.hover").mouseleave( 
				function () {
					
						$(this).fadeOut(10, function(){
			
							$(this).prev().fadeIn(500, function(){
							});
							
							$(this).closest(".pophelp").animate({
									width: '140'
								}, 200);
						
						});
					

					
					
				}
			);
						
		});
	}
	

/* =DIALOG WINDOWS
---------------------------------------------------------------------------------------*/

	function publishDialog(){
		if ($.cookie("interactiveComponents") != "disabled") {
			if ($(".dialog").length != 0) {			
				$(".dialog").each(function(){
					$("body").append($(this).hide().addClass("dialogEnabled").wrapInner("<div class='dialog-outer'><div class='dialog-inner'><div class='ui-dialog-content'></div></div></div>").prepend('<div class="ui-dialog-titlebar"><span class="ui-dialog-title">'+$(this).attr("title")+'</span><a href="#" class="ui-dialog-titlebar-close"><span>close</span></a></div>').attr("title",""));
				});
				$("a[class*='openDialog']").each(function(){
					$(this).click(function(){
						var linkClass = $(this).attr("class").match(/openDialog_(\d*)_(\d*)/);
						if (linkClass != null) {
							var dialogWidth = parseInt(linkClass[1]);
							var dialogHeight = parseInt(linkClass[2]);
						}
						openDialog(this.hash,dialogWidth,dialogHeight);
						return false;
					});
				});
				$("map area[class*='openDialog']").each(function(){
					$(this).click(function(){
						var linkClass = $(this).attr("class").match(/openDialog_(\d*)_(\d*)/);
						if (linkClass != null) {
							var dialogWidth = parseInt(linkClass[1]);
							var dialogHeight = parseInt(linkClass[2]);
						}
						openDialog(this.hash,dialogWidth,dialogHeight);
						return false;
					});
				});
			}	
		}
	}
	
	//Open Dialog
	function openDialog(dialogName, dialogWidth, dialogHeight){
		//Set up the variables
			//Dimensions
			var targetDialogWidth = dialogWidth;
			var targetDialogHeight = dialogHeight;
			var heightOfElements;
			//Get the dialog name		
			var clickTargetDialog = dialogName/*+".dialog"*/;//Removed .dialog as it is no longer needed due to the fact that there is only one instance of a dialog (ID) on the page
		//Setup the markup
			//Insert markup for the overlay
			$("body").append('<div class="dialogOverlay"></div>');
			//Dialog Dimensions
			if (targetDialogWidth == null){targetDialogWidth = 640;}
			if (targetDialogHeight == null){targetDialogHeight = 480;}
			//Overlay dimensions and fade in
			$(".dialogOverlay").height($(document).height()).animate({"opacity":"0.8"}, 400, "linear").bgiframe();
			//Set the height of the content container (subtract the title bar (32), vertical margin of the content container (0) and vertical padding of the content container (0), vertical margin/padding (0,8,18=26) of the dialog-inner container from the total dialog height (targetDialogHeight))
			//Check to see if it is a video dialog
			if ($(clickTargetDialog).hasClass("videoPlayer") == true && swfobject.hasFlashPlayerVersion("9")==true) {
				var heightOfElements = 38;//32 for title bar plus 6 pixel offset on player top
				//Set the height of the inner container. This is done b/c the CSS positioning takes the SWF element out of the flow
				$(clickTargetDialog).find(".dialog-inner").height(targetDialogHeight-heightOfElements);
			} else {
				$(clickTargetDialog).removeClass("videoPlayer");//If it has the class. This will allow any alt Flash content to display correctly.
				var heightOfElements = 58;
			}
			//Locate any video elements in the dialog and capture the id of the element
			var dialogSWFID = $(clickTargetDialog+" .flaVideo").attr("id");
			if ($(clickTargetDialog).hasClass("dialogForm") == true){
				$(clickTargetDialog).find(".ui-dialog-content").height(targetDialogHeight-heightOfElements);
			} else {
			//Set the heigth of the content container
			$(clickTargetDialog).find(".ui-dialog-content").height(targetDialogHeight-heightOfElements);
			}
		//Open the dialog
			if ($(clickTargetDialog).hasClass("dialogForm") == true){

				//Position the dialog and fade it in
				if ( !(jQuery.browser.msie && jQuery.browser.version < 7)){
					//If the browser is not IE and not less than version 7					
						$(clickTargetDialog).addClass("dialogActive").css({
							"width":      targetDialogWidth,
							"height":     targetDialogHeight,
							"margin-left":-(targetDialogWidth/2),
							"margin-top": (0)
						}).fadeIn(function(){
						});
						
				} else {
						$(clickTargetDialog).addClass("dialogActive").css({
							"width":      targetDialogWidth,
							"height":     targetDialogHeight,
							"margin-left":-(targetDialogWidth/2),
							"margin-top": (0)
						}).fadeIn(function(){
						});
				}
				
			} else {
			
				//Position the dialog and fade it in
				if ( !(jQuery.browser.msie && jQuery.browser.version < 7)){
					//If the browser is not IE and not less than version 7					
						$(clickTargetDialog).addClass("dialogActive").css({
							"width":      targetDialogWidth,
							"height":     targetDialogHeight,
							"margin-left":-(targetDialogWidth/2),
							"margin-top": -(targetDialogHeight/2)
						}).fadeIn(function(){
						});
						
				} else {
						$(clickTargetDialog).addClass("dialogActive").css({
							"width":      targetDialogWidth,
							"height":     targetDialogHeight,
							"margin-left":-(targetDialogWidth/2)
						}).fadeIn(function(){
						});
				}
				
			}
				
		//Track Event
			//Track the JS event
			trackJavaScriptEvent(clickTargetDialog, "dialog");
		//Attach close dialog events
			//Bind close to the overlay
			$(".dialogOverlay").bind("click",{dialogSWFID:dialogSWFID},function(e){
				//Remove the event so it is not bound again the next time the dialog is opened
				$(this).unbind("click");								   
				closeDialog(e.data.dialogSWFID);
				return false;				   
			});
			//Bind close to dialog close button
			$(clickTargetDialog+" .ui-dialog-titlebar-close").bind("click",{dialogSWFID:dialogSWFID},function(e){
				//Remove the event so it is not bound again the next time the dialog is opened
				$(this).unbind("click");								   
				closeDialog(e.data.dialogSWFID);
				return false;
			});
		
	}
	//
	function closeDialog(dialogSWFID){
		//If this dialog has video we need to manually pause and rewind it via the Flash ExternalInterface due to IE's behavior. Utilize a try/catch scenario so it won't fail in other browsers/scenarios.
		try {
			 if (dialogSWFID != undefined){
				flashInterface(dialogSWFID, "pauseVideoFromDoc");
			 }
		} catch (err) {
			//alert("error")
		}
		//Fade out the dialog
		$(".dialogActive").fadeOut(function(){$(this).removeClass("dialogActive");});
		//Fade out and remove the overlay
		$(".dialogOverlay").animate({"opacity":"0"}, 200, "linear", function(){
			$(this).remove();
		});
	}

/* =TEASER BAR BUMPER
---------------------------------------------------------------------------------------*/

	function publishTeaserBarBumper(){
	
		// start with the bar hidden while page loads then animate up from bottom of window
		//$(".teaserBar").hide().bgiframe();
		//$(".teaserBar").hide();
		$(".teaserBar").bgiframe();
		//$(".teaserBar").css( {visibility:'visible'} );
		//window.setTimeout('window.parent.toggleTeaser()', 2000);
		//$(".teaserBar").delay(2000).slideToggle("slow");
		//bumperTimer=setTimeout("toggleTeaser()",2000);
		//window.setTimeout("toggleTeaser()",2000);
		
		$('.teaserBar a').click(function() {
			var pageURL = location.toString();
			var pageName = encodeURIComponent(fncSliceLink(pageURL)[2]);
			openDialog("#dialog-form-news-and-offers",700,870);
			passEventParametersToMultiTrack("'DCS.dcsuri','/dtcf/components/news-and-offers','DCSext.pageName','"+pageName+"'");
			return false;
		});	
	
	}
	/*
	function toggleTeaser() {
		//clearTimeout("bumperTimer");
		$(".teaserBar").slideToggle("slow");
	}
	*/	

/* =EXPAND/COLLAPSE ACCORDION WIDGET
---------------------------------------------------------------------------------------*/

	//Global variables for accordion state management
	var expandAll;//Used by the expand/collapse all link
	var expandGroup = new Array();//Array to store the state of each accordionGroup
	//Publish the accordion control widget
	function publishAccordion(){
		//Test for accessibility features being disabled
		if ($.cookie("interactiveComponents") != "disabled") {
			//Add markup to any accordion group list items (this could cause problems if accordion groups are added outside the welcome page)
			$(".accordionGroup .accordionlist div.accordionContent").find("li:first").addClass("first");
			//Find each accordion group
			$(".accordionGroup>h3").each(function(i){
				//assign each an id of "group"+i
				$(this).attr("id", "group"+i);
			});
			//Attach the accordion group events
			accordionGroupEvents();
			//Call the expandCollapseLink function in order to initialize the event
			expandCollapseLink();
			//Find each dt
			$(".accordionlist dt").each(function (i) {
				//Add markup to the dt and the dd
				$(this).wrapInner("<span></span>").next().wrapInner("<div class='inner wrap'></div>");
				//Test to see if the accordion is set to be open on start
				if ($(this).hasClass("open")) {
				} else {
					//if it isn't open, hide it
					$(this).next().hide();
					//$(this).next().addClass("closed");
				}
				//Attach the click event to the dt
				$(this).click(function() {
					//If it's open
					if ($(this).hasClass("open")) {
						//remove the class
						$(this).removeClass("open");
					} else {
						//If not, add the class
						$(this).addClass("open");
						//When the animation completes, make the analytics call
						trackJavaScriptEvent($(this).text(), "accordion");
					}
					//Animate the opacity and height of the dd
					$(this).next().animate({opacity: 'toggle', height: 'toggle'}, function(){
						
						//and test to see if the dd is part of an accordionGroup (these are on the welcome page)
						if ($(this).parent().parent().hasClass("accordionGroup") == true){
							//If it is, call the track state function and pass the id of the group it is in by extracting that from the h3 within the group
							trackAccordionState($(this).parent().parent().find("h3:first").attr("id").substring(5));
						}
					});
				});
				//Call the trackAccordionState function on initialization to account for any manually opened accordions
				//Test to see if the dt is part of an accordionGroup
				if ($(this).parent().parent().hasClass("accordionGroup") == true){
					//If it is, call the track state function and pass the id of the group it is in by extracting that from the h3 within the group
					trackAccordionState($(this).parent().parent().find("h3:first").attr("id").substring(5));
				} else {
					trackAccordionState();
				}
			});
		}
	}
	//Track accordion state (open or close accordions within a group or all)
	function trackAccordionState(targetedGroup){
		//Variables for maintaining a count of the dt's within a group or all on a page (this function needs to be extended to allow for multiple expand/collapse/accordion controls on a page)
		var groupOpenDD=0;//Num of DDs open in a group
		var groupClosedDD=0;
		var openDD=0;//Num of DDs open on page
		var closedDD=0;
		//Count the DDs open/closed in the targeted group
		$("h3#group"+targetedGroup).parent().find(".accordionlist dt").each(function () {
			if ($(this).hasClass("open")==true){
				groupOpenDD++;
			} else {
				groupClosedDD++;
			}
		});
		//If the number of DDs open matches the total num of DDs in the group
		if (groupOpenDD == $("h3#group"+targetedGroup).parent().find(".accordionlist dt").length){
			//Set the expandGroup variable to false b/c the only action available is collapse
			expandGroup[targetedGroup] = false;
			//Set the background-position of the targeted  group's h3
			switch(targetedGroup)
			{
			case "0":
				$("h3#group"+targetedGroup).css("background-position","-56px bottom");
				break;
			case "1":
				$("h3#group"+targetedGroup).css("background-position","-168px bottom");
				break;
			case "2":
				$("h3#group"+targetedGroup).css("background-position","-280px bottom");
				break;
			default:
			}
		//If the number of DDs closed matches the total num of DDs in the group
		} else if (groupClosedDD == $("h3#group"+targetedGroup).parent().find(".accordionlist dt").length) {
			//Set the expandGroup variable to true b/c the only action available is expand
			expandGroup[targetedGroup] = true;
			//Remove the any style attributes controlling the background position of the h3 effectively setting the h3's background back to it's default
			$("h3#group"+targetedGroup).removeAttr("style");
		}
		//Count the DDs open/closed on the page		
		$(".accordionlist dt").each(function(){
			if ($(this).hasClass("open")==true){
				openDD++;
			} else {
				closedDD++;
			}
		});
		//If the number of DDs open matches the total num of DDs on the page
		if (openDD == $(".accordionlist dt").length){
			//Set the expandAll variable to false b/c the only action available is collapse
			expandAll = false;
			//Change the text and background-position of the expand/collapse link
			$("p.expandAll a").text("Collapse All");
			$("p.expandAll a").css("background-image","url(/images/interface/bgArrowBlueLightBackToTop.gif)");
			//Find all the accordionGroups
			$(".accordionlist dt").parent().parent().find("h3:first").each(function(i){
				//Set each group's expandGroup variable to false b/c the only action available is collapse
				expandGroup[i] = false;
				//Set the background-position of the targeted group's h3
				switch(i)
				{
				case 0:
					$(this).css("background-position","-56px bottom");
					break;
				case 1:
					$(this).css("background-position","-168px bottom");
					break;
				case 2:
					$(this).css("background-position","-280px bottom");
					break;
				default:
				}
			});
		//If the number of DDs closed matches the total num of DDs on the page
		} else if (closedDD == $(".accordionlist dt").length) {
			//Set the expandAll variable to true b/c the only action available is expand
			expandAll = true;
			//Change the text and remove the style controlling the background-position of the expand/collapse link
			$("p.expandAll a").text("Expand All");
			$("p.expandAll a").removeAttr("style");
			//Remove the any style attributes controlling the background position of the h3 effectively setting the h3's background back to it's default
			$(".accordionlist dt").parent().parent().find("h3:first").each(function(){
				$(this).removeAttr("style");
			});
			//Set each group's expandGroup variable to false b/c the only action available is collapse
			for (var count=0;count<=$(".accordionlist dt").length-1;count++){
				expandGroup[count] = true;
			}
		}
	}
	//Insert and control the expand/collapse all link
	function expandCollapseLink(){
		//Add the markup for the expand/collaspe link before the first accordion group
		$(".accordionGroup:first").before("<p class='expandAll'><a href='#'>Expand All</a></p>");
		//Attach the click event behavior 
		$("p.expandAll a").click(function(){
			//Test to see what action (expand/collapse) to perform
			if (expandAll == true){
				//Expand the DDs
				$(".accordionGroup .accordionlist dt").each(function (i) {
					//If it's open
					if ($(this).hasClass("open")) {
						//do nothing b/c we are expanding
					} else {
						//Animate the opacity and height of the dd
						$(this).next().animate({opacity: '1', height: '100%'}, function(){
							//and remove any existing style left from the animation behavior
							$(this).removeAttr("style");
						});
						//Add the open class to the dt b/c all the dd's are expanded
						$(this).addClass("open");
					}		
				});
			} else {
				//Collapse the DDs
				$(".accordionGroup .accordionlist dt").each(function (i) {
					//If it's open
					if ($(this).hasClass("open")) {
						$(this).next().animate({opacity: '0', height: '1'}, function(){
							//and remove any existing style left from the animation behavior and hide it
							$(this).removeAttr("style").hide();
						});
						//Remove the open class
						$(this).removeClass("open");
					}
				});
			}
			//Call the trackAccordionState function to update the tracking variables
			trackAccordionState();
			//Disable default behavior of the link
			return false;
		});
	}
	//accordion group events for hover and click
	function accordionGroupEvents(){
		//Attach hover event using jQuery hover()
		$(".accordionGroup>h3").hover(
			function () {//mouseover
				//Get the ID of the hovered h3 and strip out the "group" text
				var hoveredGroup = $(this).attr("id").substring(5);
				//test to see if the group action is to expand
				if (expandGroup[hoveredGroup] == true){
					//Set the background-position of the targeted group's h3
					switch(hoveredGroup)
					{
					case "0":
						$(this).css("background-position","-28px bottom");
						break;
					case "1":
						$(this).css("background-position","-140px bottom");
						break;
					case "2":
						$(this).css("background-position","-252px bottom");
						break;
					default:
					}
				} else {
					//If it is set to collapse, set the background-position of the targeted group's h3
					switch(hoveredGroup)
					{
					case "0":
						$(this).css("background-position","-84px bottom");
						break;
					case "1":
						$(this).css("background-position","-196px bottom");
						break;
					case "2":
						$(this).css("background-position","-308px bottom");
						break;
					default:
					}
				}
			}, 
			function () {//mouseout
				//Get the ID of the hovered h3 and strip out the "group" text
				var hoveredGroup = $(this).attr("id").substring(5);
				//test to see if the group action is to expand
				if (expandGroup[hoveredGroup] == true){
					//Remove the style for positioning the background set on mouseover
					$(this).removeAttr("style");
				} else {
					//If it is set to collapse, set the background-position of the targeted group's h3 back to the position for collapse
					switch(hoveredGroup)
					{
					case "0":
						$(this).css("background-position","-56px bottom");
						break;
					case "1":
						$(this).css("background-position","-168px bottom");
						break;
					case "2":
						$(this).css("background-position","-280px bottom");
						break;
					default:
					}
				}
			}
		);
		//Attach click event
		$(".accordionGroup>h3").click(function(){	
			//Get the ID of the hovered h3 and strip out the "group" text
			var clickedGroup = $(this).attr("id").substring(5);
			//test to see if the group action is to expand
			if (expandGroup[clickedGroup] == true){
				//Set the background-position of the targeted group's h3
				switch(clickedGroup)
				{
				case "0":
					$(this).css("background-position","-56px bottom");
					break;
				case "1":
					$(this).css("background-position","-168px bottom");
					break;
				case "2":
					$(this).css("background-position","-280px bottom");
					break;
				default:
				}
				//Find the dt's within the group				
				$(this).parent().find(".accordionlist dt").each(function (i) {
					//If it is open then don't do anything
					if ($(this).hasClass("open")) {
					} else {
						//If it is not open then animate the dd to the expanded state
						$(this).next().animate({opacity: '1', height: '100%'}, function(){
							//Remove any style attributes added for the animation
							$(this).removeAttr("style");
						});
						//Add the open class to the dt
						$(this).addClass("open");
					}		
				});
			//if the group is not expanding then it is collapsing
			} else {
				//Remove any style attributes on the h3 used to position the background thus setting it back to it's default
				$(this).removeAttr("style");									
				//Find all the dt's within the group			
				$(this).parent().find(".accordionlist dt").each(function (i) {
					//If it is open, collapse it
					if ($(this).hasClass("open")) {
						//Remove the open class from the dt
						$(this).removeClass("open");
						//Animate the dd to the collapsed state
						$(this).next().animate({opacity: '0', height: '1'}, function(){
							//Remove any style attributes added to the dd during the animation and hide it
							$(this).removeAttr("style").hide();
						});
					}
				});
			}
			//Call the trackAccordionState to update the true/false settings
			trackAccordionState(clickedGroup);
			//Disable default behavior
			return false;
		});
	}

/* =PAGE TOOLS
---------------------------------------------------------------------------------------*/

	//Hover for IE
	function sfHover() {
		if (!document.getElementById) return false;
		var sfMenus = new Array("pageTools");
		if (window.attachEvent) {
			for (var j=0; j<sfMenus.length; j++) {
				if(!document.getElementById(sfMenus[j])) return false;			
				var sfEls = document.getElementById(sfMenus[j]).getElementsByTagName("li");
				for (var i=0; i<sfEls.length; i++) {
					sfEls[i].onmouseover=function() {
						this.className+=" sfhover";
					}
					sfEls[i].onmouseout=function() {
						this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					}
				}
			}
		}
	}
	//Share menu links
	function modifyShareLinks(){
		$("ul#shareMenu a").each(function(){
			var linkURL = $(this).attr("href");
			if (linkURL.indexOf("twitter") != -1) {
				linkURL = linkURL+encodeURIComponent(location.href);
				$(this).attr("href",linkURL);
			} else if (linkURL.indexOf("facebook") != -1) {
				linkURL = linkURL+encodeURIComponent("?u="+location.href+"&t="+document.title);
				$(this).attr("href",linkURL);
			} else if (linkURL.indexOf("delicious") != -1) {
				linkURL = linkURL+encodeURIComponent("?v=5&noui&jump=close&url="+location.href+"&title="+document.title);
				$(this).attr("href",linkURL);
			} else if (linkURL.indexOf("buzz") != -1) {
				linkURL = linkURL;
				$(this).attr("href",linkURL);
			}
		});
	}
	
/* =FLASH PUBLISHING
---------------------------------------------------------------------------------------*/
	
	//Publish Flash objects
	function publishFlash() {
		
		//Remove JavaScript warning from Alt Content Notice
		$(".altCntNotice span").remove();
			
		//Assign another style to control visibility going forward - this is to ensure printing of the alternate content occurs
		$(".altFlashContent").addClass("altVisibility");
		$(".altCntNotice").addClass("altVisibility");
		
		if (!swfobject.hasFlashPlayerVersion("9")) {
			// no Flash
			$(".altFlashContent").addClass("show");
			$(".altCntNotice").addClass("show");
			//Homepage elements
			$("body.layoutHomepage .pageFooter .tout").addClass("show");
			$("body.layoutHomepage .globalUtilities").addClass("show");
			$("body.layoutHomepage .navPrimaryContainer").addClass("show");
			$("body.layoutHomepage .logo").addClass("show");
			$("body.layoutHomepage .logo").addClass("show");
			$("body.layoutHomepage #locatorTout").addClass("noFlash");
			$("body.layoutHomepage .lineImgWrap").addClass("show");	
			if ((jQuery.browser.msie && jQuery.browser.version < 7)){
				$("body.layoutHomepage .altFlashContent #dukes").attr("src","/images/content/dukes_altFlash.jpg").css("z-index","0");
			}			
 			
		}
			
		//Test to see if the visitor has disabled interactive components
		if ($.cookie("interactiveComponents") != "disabled") {
			
			//Embed Flash objects
					
			//Homepage Flash
			if ( $("div.flaPlayer #flaHome").length > 0 ) { //Check to see if the DIV exists
				//swfObject Parameters
				var flashvars = {};
					//flashvars.v_swfPath = "realize_intro.swf"; //The name of the SWF file to be loaded
					//flashvars.v_swfDataPath = "flaChartsData.xml"; //The name of the XML file referenced by the loaded SWF file
					//flashvars.v_swfWidth = "100%"; //The loaded SWF width
					//flashvars.v_swfHeight = "635"; //The loaded SWF height
					flashvars.firstVisit = $.cookie("firstVisit");
				var params = {};
					params.wmode = "transparent";
					params.allowfullscreen = "true";
					params.base = "/richmedia/home"; //The path to the SWF, XML, and other assets
				var attributes = {};
				swfobject.embedSWF("/richmedia/home/loader.swf", "flaHome"/*The ID of the div to replace*/, "100%"/*The loaded SWF width*/, "635"/*The loaded SWF height*/, "9.0.0", false, flashvars, params, attributes);
			}

			//Draw the Line Flash
			if ( $("div.flaPlayer #flaLine").length > 0 ) { //Check to see if the DIV exists
				//swfObject Parameters
				var flashvars = {};
					//flashvars.v_swfPath = "realize_intro.swf"; //The name of the SWF file to be loaded
					//flashvars.v_swfDataPath = "flaChartsData.xml"; //The name of the XML file referenced by the loaded SWF file
					//flashvars.v_swfWidth = "100%"; //The loaded SWF width
					//flashvars.v_swfHeight = "700"; //The loaded SWF height
					//flashvars.firstVisit = $.cookie("firstVisit");
				var params = {};
					params.wmode = "transparent";
					params.allowfullscreen = "true";
					params.scale = "noscale";
					params.base = "/richmedia/line"; //The path to the SWF, XML, and other assets
				var attributes = {};
				swfobject.embedSWF("/richmedia/line/htmlintro.swf", "flaLine"/*The ID of the div to replace*/, "100%"/*The loaded SWF width*/, "700"/*The loaded SWF height*/, "9.0.0", false, flashvars, params, attributes);
			}
						
			//Embed Videos
			$("div.flaPlayer div[id^='flaVideo']").each(function (i) {//Find each video
				//Capture the video's ID
				var videoID = $(this).attr("id");
				//Capture/set the dimensions
				var playerWidth;
				var playerHeight;
				var playerFormat = $(this).attr("class");
				if (playerFormat == "widescreen") {
					var playerWidth = "652";
					var playerHeight = "400";
				} else {
					var playerWidth = "492";
					var playerHeight = "400";
				}
				//swfObject Parameters
				var flashvars = {};
					flashvars.v_PageName = (fncSliceLink(location.toString())[2]+fncSliceLink(location.toString())[3]); //The container page file name and type
					flashvars.v_swfDataPath = videoID+".xml"; //The name of the XML file referenced by the loaded SWF file
					flashvars.v_swfObjectID = videoID;
					flashvars.v_swfWidth = playerWidth; //The loaded SWF width
					flashvars.v_swfHeight = playerHeight; //The loaded SWF height
				var params = {};
					params.wmode = "transparent";
					params.allowfullscreen = "true";
					params.base = "richmedia/video/"; //The path to the SWF, XML, and other assets
				var attributes = {};
					attributes.styleclass = "flaVideo "+playerFormat;
				swfobject.embedSWF("richmedia/video/flaVideoPlayer.swf", videoID/*The ID of the div to replace*/, playerWidth/*The loaded SWF width*/, playerHeight/*The loaded SWF height*/, "9.0.0", false, flashvars, params, attributes/*, callbackFn*/);
			});
									
		} else {//The visitor has disabled interactive components
			//Show the alternate content
			$(".altFlashContent").addClass("show");
			//Remove the alt content notice b/c this visitor has chosen to disable Flash
			$("p.altCntNotice").remove();
		}
		
	}

	//Write cookies from Flash
	function writeFlashCookie(cookieName, cookieValue){
		$.cookie(cookieName, cookieValue, {path: '/'});
	}
	
	//Work with Flash ExternalInterface
	function flashInterface(flashObjectID, asFunction, asFunctionArguments){
		if (asFunctionArguments == undefined){
			eval("document['"+flashObjectID+"']."+asFunction+"()");
		} else {
			eval("document['"+flashObjectID+"']."+asFunction+"("+asFunctionArguments+")");//Pass asFunctionArguments as a string in the following format "'argOne','argTwo'"
		}	
	}
	
	//Debug Flash
	function debugFlash(alertMessage){
		try {
			console.log(alertMessage);
		} catch(err) {
			alert(alertMessage);
		}
	}


	
/* =HOMEPAGE FLASH EVENTS
---------------------------------------------------------------------------------------*/

	//Fade in Logo
	function logoTrigger(){
		$("body.layoutHomepage .logo").fadeIn(1500);
	}
	//Fade in Primary Nav and Global Utilities
	function navTrigger(){
		$("body.layoutHomepage .navPrimaryContainer").fadeIn(600);
		$("body.layoutHomepage .globalUtilities").fadeIn(600);
	}
	//Fade in homepage touts
	function toutTrigger(){
		$("body.layoutHomepage").not("body.line").find("#locatorTout").css({"left":"24px","top":"-198px"});
		$("body.layoutHomepage .pageFooter .tout").fadeIn(600);
		$("body.layoutHomepage .lineImgWrap").fadeIn(600, function () {
            //publishDialog();
        });
		//Set the cookie to disabled
		$.cookie("firstVisit", false);
	}

/* =ACCESSIBILITY
---------------------------------------------------------------------------------------*/

	//Set a cookie to be used as a switch to enable/disable interacive components (Ajax and Flash)
	function toggleInteractiveElements() {
		if ($.cookie("interactiveComponents") != "disabled") {
			$("div.pageContainer").prepend("<p class='toggleInteractiveControls'>Improve accessibility to this site's content by <a href='#'>disabling interactive elements</a>.</p>");
			disableInteractiveComponents();
		} else {
			$("div.pageContainer").prepend("<p class='toggleInteractiveControls'><a href='#'>Enable interactive elements and reload the page</a>.</p>");
			enableInteractiveComponents();
		}
	}
	//Disable Interactive Components
	function disableInteractiveComponents(){
		$("p.toggleInteractiveControls a").click(function() {
			//Track event
			trackJavaScriptEvent("Disable-Interactive-Elements", "Accessibility");
			//Set the cookie to disabled
			$.cookie("interactiveComponents", "disabled");
			//Get the current page
			var currentPage = unescape(window.location.pathname);
			//Refresh the current page thus executing any functions that occur on document ready such as publish Flash
			window.location.replace(currentPage);
			return false;
		});
	}
	//Enable Interactive Components
	function enableInteractiveComponents(){
		$("p.toggleInteractiveControls a").click(function() {
			//Track event
			trackJavaScriptEvent("Enable-Interactive-Elements", "Accessibility");
			//Set the cookie to enabled
			$.cookie("interactiveComponents", "enabled");
			//Get the current page
			var currentPage = unescape(window.location.pathname);
			//Refresh the current page thus executing any functions that occur on document ready such as publish Flash
			window.location.replace(currentPage);
			return false;
		});
	}
	
/* =ANALYTICS
---------------------------------------------------------------------------------------*/
	
	//Find links and automatically add the event to trigger the WT function on click
	function fncAutoTag() {
		//Track Next Page Links
		$("div.content .nextpage a").attr("href",function(){
			var vLink = $(this).attr("href");
			var vHash = vLink.substring(vLink.indexOf("#"));
			if (vLink.indexOf('http') == -1 && vLink.indexOf('#') == -1){
				return vLink + "?DCSext.path=next";									  					
			} else if (vLink.indexOf('#') != -1) {
				return vLink.substring(0,vLink.indexOf("#")) + "?DCSext.path=next" + vHash;
			} else {
			}				
		});
		//Track Tout/Related Links
		$(".navSecondaryContainer .tout a").attr("href",function(){
			var vLink = $(this).attr("href");
			var vHash = vLink.substring(vLink.indexOf("#"));
			if (vLink.indexOf('http') == -1 && vLink.indexOf('#') == -1){
				return vLink + "?DCSext.path=tout";									  					
			} else if (vLink.indexOf('#') != -1) {
				return vLink.substring(0,vLink.indexOf("#")) + "?DCSext.path=tout" + vHash;
			} else {
			}				
		});
	}
	
	//Track JavaScript Events 
	function trackJavaScriptEvent(contentSource, widgetType) {
		var contentTitle = encodeURIComponent(jQuery.trim(contentSource));
		var contentGroup = encodeURIComponent($("meta[name='WT.cg_n']").attr("content"));
		if (contentGroup == "undefined"){
			contentGroup = "";
		}
		var subContentGroup = encodeURIComponent($("meta[name='WT.cg_s']").attr("content"));
		if (subContentGroup == "undefined"){
			subContentGroup = "";
		}
		var pageURL = location.toString();
		var pagePath = encodeURIComponent(fncSliceLink(pageURL)[1].substring( fncSliceLink(pageURL)[1], fncSliceLink(pageURL)[1].lastIndexOf( "/" ) + 1 )+widgetType);
		var pageName = encodeURIComponent(fncSliceLink(pageURL)[2]);
		var pageType = encodeURIComponent(fncSliceLink(pageURL)[3]);
		//Pass event parameter value pairs to the dcsMultiTrack function
		passEventParametersToMultiTrack("'DCS.dcsuri','"+pagePath+"/"+contentTitle+"','WT.ti','"+widgetType+":"+contentTitle+"','WT.cg_n','"+contentGroup+":RevealUse','WT.cg_s','"+subContentGroup+"','DCSext.page_name','"+pageName+pageType+"','DCSext."+widgetType+"_name','"+contentTitle+"'");
		//Build the image path
		var path = "/images/analytics/"+widgetType+"WTP.png?WT.cg_n="+contentGroup+":RevealUse&WT_cg_s="+subContentGroup+"&DCSext.page_name="+pageName+pageType+"&DCSext."+widgetType+"_name="+contentTitle;
		//Load the image
		$("body").append("<div class='wta' style='position:absolute; top:32px; left:32px; z-index:100;'><img src="+path+" style='display:none;'/></div>");
	}
	
	//Execute dcsMultiTrack
	function passEventParametersToMultiTrack(parameterValuePairs){
		try {
			eval("dcsMultiTrack("+parameterValuePairs+")");
		} catch(err){
			//alert(parameterValuePairs);
		}
	}
	
/* =FIND SURGEON RESULTS
---------------------------------------------------------------------------------------*/
	
	//Find links and automatically add the event to trigger the WT function on click
	function findSurgeonResults() {
		$(".c_locatorControlBar").eq(1).attr("id","secondControlBar");
	}

/* =CALL EVENTS
---------------------------------------------------------------------------------------*/
	$(document).ready(function(){
   		
		// fix transparent pngs for IE6
		//$(document).pngFix();
		
		//Functions to Execute
			//DOM MANIPULATION
				modifyDropDownMenus();
				addMegaMenu();
				moveGutterContents();
				addMarkupLinkedSuperScriptSymbols();
				headerStyling();
				enhanceTouts();
				fixShareStoryCTA();
				/*
				hoverImageButtons();
				hoverImages();
				*/
				
			//FORMS
				removeMarkupFormDisclaimer();
				reorganizeStyleLogin();
				styleRadioCheckboxInputs();
				pophelper();
				/*
				reorganizeCheckboxInstructionText();
				addMarkupCommunicationPref();
				addMarkupCheckboxGroup();
				showHideOtherFields();
				*/
			//INTERACTIVE ELEMENTS
				toggleInteractiveElements();
				sfHover();
				modifyShareLinks();
				publishDialog();
				publishAccordion();
				stripeTables();//Run after accordion to account for tables within accordion elements
				refineSearchHover();
				findSurgeonResults();
				publishTeaserBarBumper();
			//ANALYTICS
				fncAutoTag();
			//FLASH
				publishFlash();
		//Events to Attach
			//FORMS
				//hoverMiniSearchGoButton();
				enhanceMiniSearchField();
				//hoverFormInputButtons();
	});




	