(function($) {	// Global functions that need to run on every page to setup various interface elements	$(function() {			/* Setup the main navigation		----------------------------------------------------*/		(function(){					var subNavTimer;						var globalNav = $("#navGlobal");					$("#navGlobal > li").bind("mouseover", function() {							$(this).addClass("over");										}).bind("mouseout", function() {							$(this).removeClass("over");							});						globalNav.find("ul.subNav li").bind("mouseover", function() {				$(this).addClass("over");				$(this).siblings().removeClass("over");				$(this).find(".promo").addShim();				clearTimeout(subNavTimer);								//remove any shims on other promo items (not the current one)				$(this).siblings().find(".promo").removeShim();							}).bind("mouseout", function() {				var subNavItem = $(this);				subNavTimer = setTimeout(function(){					subNavItem.removeClass("over");					subNavItem.find(".promo").removeShim();				}, 100);			});						//Add focus handling to aid in keyboard navigation			var navTimer;						globalNav.find("li a").bind("focus", function() {							//If it's a sub-menu link, make sure the sub-menu stays open and the main nav item still shows as "over"				if ($(this).parents(".subNav").length > 0) {					$(this).parent().trigger("mouseover");					clearTimeout(navTimer);				}				$(this).parent().trigger("mouseover");										}).bind("blur", function() {							var navItem = $(this);				//Set a slight delay before firing the mouseout event for this nav item (which will remove the "over" class and cause the sub menu to be hidden again). This delay will be cancelled out if the next item to get focus is still inside the currently visible sub menu.				navTimer = setTimeout(function() {					navItem.parent().trigger("mouseout");				}, 50);							});						})();									/* Setup the Search form in the nav		----------------------------------------------------*/		(function() {						var searchLabel = $("#frmSearch label");			var searchField = $("#frmSearch #txtSearch");						searchLabel.hide();			searchField.val(searchLabel.text());				//Event handlers			searchField.bind("focus", function() {				if ($(this).val() == searchLabel.text()) {					//Clear the text field					searchField.val("");				}			});			searchField.bind("blur", function() {				if ($.trim($(this).val()) == "") {					searchField.val(searchLabel.text());				}			});					})();							/* Hide the Site Map and setup the events for it		----------------------------------------------------*/		(function() {			var siteMap = $("#siteMap");			siteMap.hide();						//setup event handling for the sitemap link			$("#siteMapLink").bind("click", function() {							var siteMapLink = $(this);								if(siteMap.is(".open")) {					siteMap.slideUp(1000, function() {								siteMapLink.removeClass("open");										}).removeClass("open");				}				else {					siteMap.slideDown(50, function() {											//scroll to the siteMapLink (which will make sure that the sitemap is in view)						siteMapLink.scrollTo({							speed: 1000,							afterScroll: function() {								siteMapLink.addClass("open");							}						});										}).addClass("open");				}								return false;						});		})();						/* Convert low-res buttons to high-res buttons		----------------------------------------------------*/		$(".sprint input[type='submit'], .sprint input[type='button'], .sprint a.button1, .sprint a.button2, .sprint a.button3, .sprint a.button4, .sprint a.flyout").createHighResButtons();		/* Setup all default components with default values except for buttons		----------------------------------------------------*/		$().setupComponents({			modals: true,			buttons: false		});						/* Adds Print button to container		----------------------------------------------------*/		/* $(".printButtonContainer").each(function() {			$(this).append("<div class=\"button4AltIcon\"><a href=\"#\" onclick=\"window.print(); return false;\" id=\"btnPrint\" class=\"functionPrint\"><span>Print</span></a></div>");		}); */		$(".printButtonContainer").show();						/* Default Error Messaging Behaviour		----------------------------------------------------*/		$("ul.formErrors li a").live("click", function() {					//Find the anchor target that this error links to			var anchorTarget = $(this).attr("href");						//strip off everything before the "#"			anchorTarget = anchorTarget.substr(anchorTarget.indexOf("#"));						$(anchorTarget).scrollTo({speed: "slow"});						//Set focus to the field that the label represents and select any text that may be inside			$("#"+$(anchorTarget).attr("for")).trigger("focus").trigger("select");						return false;				});								/* Sign-In		-------------------------------------------------*/		(function() {					var submitLoginForm = false;						var frmUserLogin = $("#frmUserLogin");								//Make sure form submission goes through the Sign In button.			frmUserLogin.bind("submit", function(event) {				if (!submitLoginForm) {					event.preventDefault();										frmUserLogin.find("#btnLoginSubmit").trigger("click");				}							});						frmUserLogin.find("#btnLoginSubmit").unbind("click").bind("click", function(event) {				event.preventDefault();								//Submit the form using an AJAX request.				var formPath = frmUserLogin.attr("action");								$.ajax({										data: frmUserLogin.serialize(),					type: "POST",					url: formPath,					dataType: "json",										success: function(data) {												//Remove any previous error messages						frmUserLogin.find("ul.formErrors").remove();						frmUserLogin.find(".error").removeClass("error");						if (data.validated) {																	//Submit the registration form.							window.location = data.nextPage;						}						else if (data.accountLocked) {							//Account locked, show account locked message.							var errorList = $("<ul class=\"formErrors\"><li>"+data.accountLockedErrorHeader+"</li></ul><p>"+data.accountLockedErrorMessage+"</p>");														//Empty the form, change it's action, put in the new fields							frmUserLogin.attr("action", data.accountResetPath);							frmUserLogin.find("fieldset").html(errorList);														//Reset checkbox							var resetCheck = $("<div><label for=\"chkLoginAccountReset\" id=\"lblLoginAccountReset\"><input type=\"checkbox\" class=\"check\" name=\"chkLoginAccountReset\" id=\"chkLoginAccountReset\" /> "+data.accountLockedResetLabel+"</label></div>");														resetCheck.appendTo(frmUserLogin.find("fieldset"));																					//Put in the new submit button.							var newSubmitButton = $("<input type=\"submit\" class=\"button1\" id=\"btnLoginSubmit\" value=\""+data.accountResetButtonLabel+"\" />");														newSubmitButton.appendTo(frmUserLogin.find("fieldset"));														newSubmitButton.wrap("<div class=\"buttons\"></div>");														newSubmitButton.createHighResButtons();														$("#btnLoginSubmit").unbind("click").bind("click", function(event) {																event.preventDefault();																//if the reset account checkbox is checked, submit the form. If not, do nothing.								if ($("#chkLoginAccountReset").is(":checked")) {									submitLoginForm = true;																		frmUserLogin.eq(0).submit();								}															});						}						else {														//Build the error message list							var errorList = $("<ul class=\"formErrors\"></ul>");														for (i = 0; i < data.errors.length; i++) {								var errorItem = $("<li><a href=\"#"+data.errors[i].field+"\">"+data.errors[i].errorMessage+"</a></li>");								errorItem.appendTo(errorList);																$("#"+data.errors[i].field).addClass("error");							}														errorList.find("a").bind("click", function() {								//Find the anchor target that this error links to								var anchorTarget = $(this).attr("href");																//strip off everything before the "#"								anchorTarget = anchorTarget.substr(anchorTarget.indexOf("#"));																//Set focus to the field that the label represents and select any text that may be inside								$(anchorTarget).trigger("focus").trigger("select");																return false;							});														//Show the error message list.							frmUserLogin.find("fieldset").prepend(errorList);						}											},										error: function(event) {						alert("error communicating with server\n\nStatus: "+event.status);					}								});							});					$("#userLoginContent").addRoundedCorners();							var userLogin = $("#userLogin");						var signInLink = $("#signInLink");						var navUser = $("#navUser");					userLogin.disclosure({				startClosed:     true,				titleClickable:  false,				speed:           "fast",				openedText:      Sprint.content.userLoginDisclosure.openedText[Sprint.currentLanguage],				closedText:      Sprint.content.userLoginDisclosure.closedText[Sprint.currentLanguage],								openCallback:    function() {					userLogin.addShim(); //Add an iframe shim (for IE6)										function removeShim() {						userLogin.removeShim(); //Remove iframe shim (for IE6)												//Once the shim has been removed, get rid of the click function						userLogin.find(".disclosureToggle").unbind("click", removeShim);					}										userLogin.find(".disclosureToggle").bind("click", removeShim);				},								closeCallback:   function() {									userLogin.hide();					navUser.animate({						width: signInLink.outerWidth()					}, function() {						signInLink.fadeIn("fast");					});				}							}).hide();					signInLink.bind("click", function() {							$(this).parent().width($(this).outerWidth());							$(this).fadeOut("fast", function() {					navUser.animate({						width: "285px"					}, function() {						userLogin.show();						userLogin.find(".disclosureToggle").trigger("click");					});				});							return false;			});				})();		/* Signed In User Nav		-------------------------------------------------*/		(function() {					var userLoggedIn = $("#userLoggedIn");						var signOutLink = $("#signOutLink");						var navUser = $("#navUser");						var loggedInUserLink = $("#loggedInUserLink");					$("#userLoggedInContent").addRoundedCorners();					userLoggedIn.disclosure({				startClosed:     true,				openedText:     Sprint.content.userLoggedInDisclosure.openedText[Sprint.currentLanguage],				closedText:     Sprint.content.userLoggedInDisclosure.openedText[Sprint.currentLanguage],								openCallback:    function() {					userLoggedIn.addShim(); //Add an iframe shim (for IE6)										function removeShim() {						userLoggedIn.removeShim(); //Remove iframe shim (for IE6)												//Once the shim has been removed, get rid of the click function						userLoggedIn.find(".disclosureToggle").unbind("click", removeShim);					}										userLoggedIn.find(".disclosureToggle").bind("click", removeShim);				},				closeCallback:  function() {									userLoggedIn.hide();										navUser.animate({						width: (signOutLink.outerWidth(true) + loggedInUserLink.outerWidth(true))					}, function() {						signOutLink.fadeIn("fast");						loggedInUserLink.fadeIn("fast");					});									}							}).hide();						loggedInUserLink.bind("click", function() {				$(this).parent().width($(this).outerWidth(true));				signOutLink.parent().width(signOutLink.outerWidth(true));												signOutLink.fadeOut("fast");				$(this).fadeOut("fast", function() {									navUser.animate({						width: "285px"					}, function() {						userLoggedIn.show();						userLoggedIn.find(".disclosureToggle").trigger("click");					});								});								return false;			});				})();		/* Find a Store Form (in the Contact Us module in the side bar)		-------------------------------------------------*/		(function() {					var frmFindStore = $("#frmFindStore");						if (frmFindStore.length > 0) {							var locationDisplay = $("#locationDisplay");								locationDisplay.hide();								locationDisplay.find("ul.storeLocatorLink li a").bind("click", function(event) {									event.preventDefault();										if ($(this).is(".changeLocation")) {						locationDisplay.hide();						frmFindStore.parent().show();												frmFindStore.find("#btnFindStore").removeClass("disabled");												frmFindStore.find("#txtFindStoreAddress").focus().select();					}					else if ($(this).is(".seeAll")) {												/*						$("#frmViewAllStores").find("input[name='r']").val(frmFindStore.find("#hidFindStoreRadius").val());						$("#frmViewAllStores").find("input[name='addr']").val($.trim(frmFindStore.find("#txtFindStoreAddress").val()));																		$("#frmViewAllStores").trigger("submit");												*/					}								});								frmFindStore.bind("submit", function(event) {									event.preventDefault();										frmFindStore.find("#btnFindStore").trigger("click");								});							function findStores(event, supressErrors){					if(event){	event.preventDefault();	}										if( supressErrors==null ){ supressErrors=false;}										if ($(this).is(".disabled")) {						return false;					}										var searchString = $.trim(frmFindStore.find("#txtFindStoreAddress").val());										$(this).addClass("disabled");														var errorFunction = Sprint.fn.ajaxError;					if(supressErrors){						errorFunction = function(){return true};					}										//Send an AJAX request to get the store data for the address entered.					$.ajax({											url: frmFindStore.attr("action"),												data: {							addr: searchString,							r: frmFindStore.find("#hidFindStoreRadius").val()						},												type: "GET",												dataType: "json",												success: function(data) {													//Remove any previous results							locationDisplay.find(".storeLocation").remove();													if (data.error) {								locationDisplay.prepend("<div class=\"storeLocation\"><h5>"+data.error+"</h5></div>");							}							else if (data.stores) {															var outputString = "";															//No errors, output the first 2 results								$.each(data.stores, function(i) {																	if (i >= 2) {										return;									}																		outputString = outputString+"<div class=\"storeLocation\"><h5>"+data.stores[i].name+"</h5><div class=\"locationTelephone\"><em>"+data.stores[i].phone+"</em></div><div class=\"locationAddress01\">"+data.stores[i].address+"</div></div>";																	});															locationDisplay.prepend(outputString);														}														frmFindStore.parent().hide();														locationDisplay.show();												},												error: errorFunction					});										}//end of findStores							frmFindStore.find("#btnFindStore").unbind("click").bind("click", function(event) {					findStores(event);				});							$(window).load( function(){					//initialize the store locator, but supress error messages					findStores(null, true);				});			}							})();								/* Form Enter-key support for Internet Explorer (because buttons are hidden, enter doesn't submit the form, this fixes that) */		if ($.browser.msie) {			$(document).bind("keydown", function(event) {				if (event.keyCode == 13) {									sourceElement = $(event.srcElement);					parentForm = sourceElement.parents("form");									if (parentForm.length > 0) {											event.preventDefault();												//Submit this item's parent form.						parentForm.trigger("submit");										}				}			});					}			});	})(jQuery);