if (!sbweb.ui) sbweb.ui = function(){
	var ON_DROPDOWN = 0;
	var AKAMAI_URL = "";
	
	var windowEvent = {
		init: function(time){
			windowEvent.timer = window.setInterval(windowEvent.animate, time);
		},
		animate: function(){
			$("#logoContainer").animate({opacity:1},1100, function() {
				$("#entranceSurveyButton").css({border:"1px solid #FFFFFF",background:"none"});
				$("#entranceSurveyOpenTab").css({background:"none"});
				$(".surveyButtonLeftEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-lt.gif) no-repeat"});
				$(".surveyButtonRightEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-rt.gif) no-repeat"});
				window.clearInterval(windowEvent.timer);
			});
			$("#entranceSurveyFormContainer").slideUp(1000);

		},
		timer: null
	};
	
	function headerSetDropdownPosition(pLinkId,pDestinationId) {
		var position = $(pLinkId).offset();
		var positionTop = 0;
		var positionLeft = 0;
		
		if (position) {
			positionTop = position.top + 26;
			positionLeft = position.left;
			$(pDestinationId).css({top: positionTop,left: positionLeft});
		}
	}
	
	function headerBindClick(pAnchorId,pLinkId,pDropdownId,pImageId,pSpeed) {
		$(pAnchorId).click(function() {
			if ($(pDropdownId + ":hidden").length > 0) {
				$(pLinkId).css({border:"1px solid #ccc",background:"url(/sbweb/common/images/header/background/bg_gradient_button.gif) repeat-x top"});
				$("#entranceSurveyOpenTab").css({background:"white"});
				$(".surveyButtonLeftEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-straight-lt.gif) no-repeat"});
				$(".surveyButtonRightEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-straight-rt.gif) no-repeat"});
				$("#logoContainer").animate({opacity:1},100, function() {
					$(pDropdownId).slideDown(pSpeed);
				});
			}
			else {
				$(pDropdownId).slideUp(pSpeed);
				$("#logoContainer").animate({opacity:1},(pSpeed + 100), function() {
					$("#entranceSurveyOpenTab").css({background:"none"});
					$(".surveyButtonLeftEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-lt.gif) no-repeat"});
					$(".surveyButtonRightEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-rt.gif) no-repeat"});
					$(pLinkId).css({border:"1px solid #FFFFFF",background:"none"});
				});
			}
		});
	}
	
	function headerBindCountry(){
		var ON_HOVER = 0;
		var t = 0;
		var t2 = 0;
		
		$("#countrySelectorButton").hover(
			function(){
				ON_HOVER = 1;
				$("#countrySelectorLeftEdge").css({
					background: "url(" + AKAMAI_URL + "/sbweb/common/images/header/country_selector/usChange-bg-tab-lt.gif) no-repeat"
				});
				$("#countrySelectorFlag").css({
					background: "url(" + AKAMAI_URL + "/sbweb/common/images/header/country_selector/usChange-bg-tab-center.gif) repeat-x"
				});
				$("#countrySelectorText").css({
					background: "url(" + AKAMAI_URL + "/sbweb/common/images/header/country_selector/usChange-bg-tab-center.gif) repeat-x"
				});
				$("#countrySelectorArrow").css({
					background: "url(" + AKAMAI_URL + "/sbweb/common/images/header/country_selector/usChange-bg-tab-center.gif) repeat-x"
				});
				$("#countrySelectorRightEdge").css({
					background: "url(" + AKAMAI_URL + "/sbweb/common/images/header/country_selector/usChange-bg-tab-rt.gif) no-repeat"
				});
			},
			function(){
				$("#countrySelectorLeftEdge").css({background:"none"});
				$("#countrySelectorFlag").css({background:"none"});
				$("#countrySelectorText").css({background:"none"});
				$("#countrySelectorArrow").css({background:"none"});
				$("#countrySelectorRightEdge").css({background:"none"});
				$("#experienceSurveyContainer").css('z-index', 100001);
				ON_HOVER = 0;
				t = setTimeout(function(){
					t = 0; //ensures counter starts at 0
					if (ON_HOVER == 0) {
						$("#countrySelectorMenu").hide();
						ON_HOVER = 0;
					}
				}, 1500);
			}
		);
		
		$("#countrySelectorButton").click(function() {
			t = 0;
			if ($("#countrySelectorMenu"+ ":hidden").length > 0) {
				$("#experienceSurveyContainer").css('z-index', 100000);
					$("#countrySelectorMenu").show();
			}
		});
		
		$("#countrySelectorMenu").hover(
			function(){
				ON_HOVER = 1;
			},
			function(){
				ON_HOVER = 0;
				t2 = setTimeout(function(){
					t2 = 0; //ensures counter starts at 0
					if (ON_HOVER == 0) {
						$("#countrySelectorMenu").hide();
						ON_HOVER = 0;
					}
				}, 1500);
			}
		);
		
	}
	
	function headerBindContact() {
		$("#contactSelectDropdown").click(function() {
			if ($("#contactNumberDropdown:hidden").length > 0) {
				$("#contactNumberDropdown").slideDown(250);
				$("#contactSelectContainer").css({background:"url(/sbweb/common/images/header/background/bg_gradient_inverted_small.gif) repeat-x top"});
			}
			else {
				$("#contactNumberDropdown").slideUp(250, function() {
					$("#contactSelectContainer").css({background: "none"});
				});
			}
		});
		
		$("#contactSelectDropdown").hover(
			function() {
				$("#contactSelectDropdown").css({color:"#365ebf"});
			},
			function() {
				$("#contactSelectDropdown").css({color:"#505050"});
			}
		);
		
		if ($("#contactSelectContainer").length == 0) {
			$("#contactFormContainer").css({height:"108px"})
		}
	}
	
	function headerBindSignIn(){
		$("#signInBar").hover(
			function(){
				if ($("#menuSignInDropDown" + ":hidden").length > 0) {
					$("#signInContainer").css("background", "url(/sbweb/common/images/header/sign_in/btn-signIn-hover.gif) no-repeat bottom left");
					$("#menuSignInDropDown").slideDown(1000);
				}
			},
			function(){
				var t = setTimeout(function(){
					if (ON_DROPDOWN < 1) {
						$("#menuSignInDropDown").slideUp(1000, function(){
							$("#signInContainer").css("background","url(/sbweb/common/images/header/sign_in/btn-signIn.gif) no-repeat bottom left");
						});
					}
				}, 500);
			}
		);
		
		$("#menuSignInLinksContainer").hover(
			function(){
				ON_DROPDOWN++;
			},
			function(){
				$("#menuSignInDropDown").slideUp(1000, function(){
					$("#signInContainer").css("background","url(/sbweb/common/images/header/sign_in/btn-signIn.gif) no-repeat bottom left");
				});
				ON_DROPDOWN = 0;
			}
		);
	}
	
	function headerBindSurvey() {
		$("#entranceSurveyFormContainer").mouseover(function() {
	        window.clearInterval(windowEvent.timer);
	    });
		
		$("#closeSurvey").click(function(){
			$("#entranceSurveyFormContainer").slideUp(1000);
			$("#logoContainer").animate({opacity:1},1100, function() {
				$("#entranceSurveyButton").css({border:"1px solid #FFFFFF",background:"none"});
				$("#entranceSurveyOpenTab").css({background:"none"});
				$(".surveyButtonLeftEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-lt.gif) no-repeat"});
				$(".surveyButtonRightEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-rt.gif) no-repeat"});
			});
		});
		
		$("#submitGlobalSurvey").click(function(){
			$("#entranceSurveyFormContainer").slideUp(1000);
			$("#logoContainer").animate({opacity:1},1100, function() {
				$("#entranceSurveyButton").css({border:"1px solid #FFFFFF",background:"none"});
				$("#entranceSurveyOpenTab").css({background:"none"});
				$(".surveyButtonLeftEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-lt.gif) no-repeat"});
				$(".surveyButtonRightEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-rt.gif) no-repeat"});
			});
		});
		
		if (sbweb.util.cookies.getCookie("SurveyClosed") == false) {
			//$("#entranceSurveyButton").css({border:"1px solid #ccc",background:"url(/sbweb/common/images/header/background/bg_gradient_button.gif) repeat-x top"});
			$("#entranceSurveyButton").css({border:"1px solid #ccc",background:"url(/sbweb/common/images/header/background/bg_gradient_button.gif) repeat-x top"});
			$("#entranceSurveyOpenTab").css({background:"white"});
			$(".surveyButtonLeftEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-straight-lt.gif) no-repeat"});
			$(".surveyButtonRightEdge").css({background:"url(/sbweb/common/images/header/survey/quick-survey-tab-straight-rt.gif) no-repeat"});
			$("#logoContainer").animate({opacity:1},100, function() {
				$("#entranceSurveyFormContainer").slideDown(1000);
			});
			windowEvent.init(4000);
			sbweb.util.cookies.setCookie("SurveyClosed",true,'Thu, 31-Dec-2020 00:00:00 GMT',ROOT_LEVEL_LOCAL,COOKIE_DOMAIN_LOCAL);
		}
	}
	
	return {
		
		init: function() {
			AKAMAI_URL = sbweb.util.url.getAkamaiUrl();
		},
		
		bindHeaderElements: function(pScope) {
			
			// Set position for dropdowns
			//headerSetDropdownPosition("#countryLinkContainer","#countryFormContainer");
			headerSetDropdownPosition("#contactLinkContainer","#contactFormContainer");
			
			// Bind click events to the link container elements
			//headerBindClick("#countryAnchor","#countryLinkContainer","#countryFormContainer",null,500);
			headerBindClick("#contactAnchor","#contactLinkContainer","#contactFormContainer","#contactFormImage",500);
			headerBindClick("#entranceSurveyAnchor","#entranceSurveyButton","#entranceSurveyFormContainer","#entranceSurveyImage",1000);
			
			// Bind header dropdown elements
			headerBindCountry();
			headerBindContact();
			headerBindSignIn();
			headerBindSurvey();
		},
		
		bindSectionExpander: function(pScope) {
			sbweb.util.log.debug("Bind section expander: " + pScope);
			$(".sectionHeader").unbind();
			$(".sectionHeader").toggle(
				function(){
					$(this).addClass("select").next().slideDown("slow");
				},
				function(){
					$(this).removeClass("select").next().slideUp("slow");
				}
			);	
		},
		
		bindFootnoteExpander: function (pScope) {
			var containerSelect = ".footnotesContainer";
			var headerSelect = ".footnotesHeaderContent";
			var headerDiv = ".footnotesHeader";
			
			sbweb.util.log.debug("Bind footnote expander: " + pScope);
			$(headerDiv).unbind();
			$(headerDiv).toggle(
				function(){
					sbweb.util.log.debug("Footnote toogle down: " + pScope);
					$(this).next().slideDown("slow");
				},
				function(){
					sbweb.util.log.debug("Footnote toogle up: " + pScope);
					$(this).next().slideUp("slow");
				}
			);
			
			sbweb.util.log.debug("Bind footnote hover: " + pScope);
			$(headerDiv).hover (
				function () {
					sbweb.util.log.debug("Footnote hover blue: " + pScope);
					$(this).css("text-decoration", "underline");
				}, 
				function () {
					sbweb.util.log.debug("Footnote unhover gray: " + pScope);
					$(this).css("text-decoration", "none");
				}
			);
		},		
			
		anchorSelectTab: function(pScope) {
			sbweb.util.log.debug("Bind tab anchor click: " + pScope);
			
			$('div.ui-tabs-panel a[name^=#]').click(
				function(){ 
					var t = $(this).attr("name");
				    $("#tabs").tabs("select", t);
					return(false);
				}
			);
		},
		
		jQueryDialog: function() {
			$('#mainBody').append('<div id="jModal"><iframe class="jdiFrame" src="/commerce/common/fragments/blank.jsp" frameborder="0"></iframe></div>');
			
			$('#jModal').dialog({
				autoOpen: false,
				draggable: false,
				resizable: false,
				stack: false,
				modal: true,
				zIndex: 100000,
				beforeclose: function(event, ui){ //fix IE flash unable to unload problem
					$('.jdiFrame').attr('src', '');
				}
			});
			$('a.jModal').click(function(){
				var url = $(this).attr("rel");
				var width = $(this).attr("width");
				var height = $(this).attr("height");
				sbweb.ui.jModalOpen(url, width, height);
				return(false);
			});
		},
		
		jModalOpen: function(url,width,height) {
			$('.jdiFrame').attr('width',width).attr('height',height).attr('src',url);
	  		width = parseInt(width) + 50;
	  		height = parseInt(height) + 50;
	  		$('#jModal').dialog('option', 'width', width).dialog('option', 'height', height).dialog('open');
		},
		
		jModalClose: function() {
			$('#jModal').dialog('close');
		},
		
		commerceTab: function() {
			// url anchor to commerce display tab
			var anchor=location.hash;		
			anchor=anchor.replace(/#/,"");
			// div.ui-tabs-panel anchor match detect 
			$("div.tabPanel").each(function (i) {			
				if (this.id == anchor) {
						$('div.cdTabList div').removeClass('activeTab');
						$('div.tabPanel').hide();
						$('div.cdTabList div:eq('+i+')').addClass('activeTab');
						$('div.tabPanel:eq('+i+')').show();
						return false;
				} else {
						$('div.cdTabList div:eq(0)').addClass('activeTab');
						$('div.tabPanel:eq(0)').show();
				}
	    });		
	
			// Commerce display tab handlers
			$('#tabbedCD .cdTabList a').click(function(){ //When any link is clicked
				$('#tabbedCD div').removeClass('activeTab'); // Remove active class from all links
				$(this).parent().addClass('activeTab'); //Set clicked link class to active			
				var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
				$('#tabbedCD div.tabPanel').hide(); // Hide all divs
				$(currentTab).show(); // Show div with id equal to variable currentTab
				return false;
			});
		},
		
		tbPreload: function(pScope) {
			sbweb.util.log.debug("Thickbox binding reset: " + pScope);
			
			$(".thickbox, area.thickbox, input.thickbox").unbind();
			tb_init("a.thickbox, area.thickbox, input.thickbox");
			imgLoader = new Image();
			imgLoader.src = tb_pathToImage;
		},
		
		jModalPreload : function(pScope){
			sbweb.util.log.debug("JModal binding reset: " + pScope);
			$('a.jModal').unbind();
			sbweb.ui.jQueryDialog();
		}
	};
}();