if (!sbweb.ui) sbweb.ui = function(){
	var AKAMAI_URL = "";
	var gCacheImgs = [];
	
	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").addClass("ss-rounded-corners").css("background-position", "0px -58px");
				$("#countrySelectorFlag").css({
					background: "url(" + AKAMAI_URL + "/sbweb/common/images/sprites/gradients/gradients-shared.gif) 0px -28px repeat-x"
				});
				$("#countrySelectorText").css({
					background: "url(" + AKAMAI_URL + "/sbweb/common/images/sprites/gradients/gradients-shared.gif) 0px -28px repeat-x"
				});
				$("#countrySelectorArrow").css({
					background: "url(" + AKAMAI_URL + "/sbweb/common/images/sprites/gradients/gradients-shared.gif) 0px -28px repeat-x"
				});
				$("#countrySelectorRightEdge").addClass("ss-rounded-corners").css("background-position", "-4px -58px");
			},
			function(){
				$("#countrySelectorLeftEdge").removeClass("ss-rounded-corners");
				$("#countrySelectorFlag").css({background:"none"});
				$("#countrySelectorText").css({background:"none"});
				$("#countrySelectorArrow").css({background:"none"});
				$("#countrySelectorRightEdge").removeClass("ss-rounded-corners");
				$("#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(){
		var DROPDOWN_TIMER;
		
		$("#signInContainer, #menuSignInDropDown").hover(
			// on hover
			function(){
				clearTimeout(DROPDOWN_TIMER);
				if ($("#menuSignInDropDown" + ":hidden").length > 0) {
					$("#signInContainer").css("background-position", "-63px -22px");
					$("#menuSignInDropDown").show();
				}
			},
			// off hover
			function(){ 
				clearTimeout(DROPDOWN_TIMER);
				// dropdown closes after a short delay
				DROPDOWN_TIMER = setTimeout(function(){
					$("#menuSignInDropDown").hide(1, function(){
						$("#signInContainer").css("background-position","0px -22px");
					});
				}, 500);
			}
		);
	}
	
	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();
		},
		
		bindImgSwap: function(){
			
			var off_hover_src, hover_src, src_array;
			
			$("#imageSwap").hover(onButton,offButton);
			$(".imageSwap").hover(onButton,offButton);
			 
			function onButton(){
				off_hover_src = $(this).attr("src");
				src_array = off_hover_src.split(".");
				hover_src = src_array[0] + "_hover." + src_array[1];
				$(this).attr("src", hover_src);
			};
			
			function offButton(){
				$(this).attr("src", off_hover_src);
			};
		},
		
		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");
				}
			);
			
			// divs using expander-parent/expander-child class
			$(".expander-parent").unbind();
			$(".expander-parent").toggle(
				function(){
					$(this).next().slideDown("slow");
				},
				function(){
					$(this).next().slideUp("slow");
				}
			);	
			
			// links to expand/collapse all
			$(".expand-all").click(
				function(){
					$(".expander-child").slideDown("slow");
				}
			);
			$(".collapse-all").click(
				function(){
					$(".expander-child").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");
				}
			);
		},		
		
		bindTabDisplay: function (pScope) {
			$(".tabParent").click(displayTabContent);
			
			function displayTabContent(){
				var tabId, parentId;
				
				// Get tabId and parentId
				tabId = $(this).attr("id");
				parentId = $(this).parent().parent().attr("id");
				
				// Hides all tab content and removes any selected classes
				$(parentId + " li a").removeClass("selected");
				$(".tabChild").hide();
				
				// Set tab to selected and display selected tab content
				$(this).addClass("selected");
				$(this + "_content").show();
			}
		},	
			
		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="javascript:false;" 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, width, height, scrolling;
				
				if ($(this).attr("rel")!= ""){
					// Checks legacy jmodal implmentation.  Takes "rel" attribute for URL along with other attributes in anchor tag.
					url = $(this).attr("rel");
					width = $(this).attr("width");
					height = $(this).attr("height");
					scrolling = $(this).attr("scrolling");
				}
				else{
					url = $(this).attr("href");
					var query = url.split("?");
					var vars = query[1].split("&");
					
					for (var i = 0; i < vars.length; i++) {
						var pair = vars[i].split("=");
						switch (pair[0]){
							case "width":width=pair[1];break;
							case "height":height=pair[1];break;
							case "scrolling":scrolling=pair[1];break;
							default:break;
						}
					}
				}
				
				sbweb.ui.jModalOpen(url, width, height,scrolling);
				return(false);
			});
				
		$('a.addScroll').click(function(){
				var url, width, height, scrolling, scrollto;
				
				if ($(this).attr("rel")!= ""){
					// Checks legacy jmodal implmentation.  Takes "rel" attribute for URL along with other attributes in anchor tag.
					url = $(this).attr("rel");
					width = $(this).attr("width");
					height = $(this).attr("height");
					scrolling = $(this).attr("scrolling");
					scrollto = $(this).attr("scrollto");
				}
				else{
					url = $(this).attr("href");
					var query = url.split("?");
					var vars = query[1].split("&");
					
					for (var i = 0; i < vars.length; i++) {
						var pair = vars[i].split("=");
						switch (pair[0]){
							case "width":width=pair[1];break;
							case "height":height=pair[1];break;
							case "scrolling":scrolling=pair[1];break;
							case "scrollto":scrollto=pair[1];break;
							default:break;
						}
					}
				}
				
				//sbweb.ui.jModalOpen(url, width, height,scrolling);
				
				if(scrollto != null && scrollto.length > 0){
					a = scrollto.split(",");
					b = a[0];
					c = a[1];
					//alert("q-b is "+b+" and c is "+c);
					window.scrollTo(b,c);
				}
				return(false);
			});
		},
		jModalOpen: function(url,width,height,scrolling) {
			$('.jdiFrame').attr('width',width).attr('height',height).attr('src',url).attr('scrolling',scrolling);
	  		width = parseInt(width) + 20;
	  		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(/#tab/,"");
			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();
		},
		
		/*-------------------------- Image Preload -----------------------------*/
		preloadImages : function() {
			// Build image src url
			var prefix = "";
			if (location.protocol == 'http:') {
				if(location.href.indexOf(".com:") < 0){
					prefix = "http://" + location.hostname;
				}
				else{
					var position = location.href.indexOf(".com:");
					prefix = "http://" + location.hostname + location.href.substring(position + 4, position + 9);
				}
			}
		 	
			// Preload all images passed in function arguments
			for(var i = 0; i<arguments.length; i++)	{
				imgPreLoad = new Image();
				imgPreLoad.src = prefix + arguments[i];
			}
		},
		
		// Allows the use of absolute url, like in situations where you want to cache an img from akamai
		preloadImagesAbsUrl : function() {
			var args_len = arguments.length;
			for (var i = args_len; i--;) {
				var cacheImg = document.createElement("img");
				cacheImg.src = arguments[i];
				gCacheImgs.push(cacheImg);
			}
		}
		/*----------------------------- Function End ------------------------------------*/
	};
}();
