if (!sbweb.ui) sbweb.ui = function(){
	
	var HEADER_ARROW_OVER = "/sbweb/common/images/header/contact_us/header_arrow_over.gif";
	var HEADER_ARROW_OFF = "/sbweb/common/images/header/contact_us/header_arrow_off.gif";
	
	$("<img>").attr("src", HEADER_ARROW_OVER);
	
	var windowEvent = {
		init: function(time){
			windowEvent.timer = window.setInterval(windowEvent.animate, time);
		},
		animate: function(){
			$("#entranceSurveyFormContainer").slideUp(1000);
			$("#logoContainer").animate({opacity:1},1100, function() {
				$("#entranceSurveyImage").attr("src", HEADER_ARROW_OFF);
				$("#entranceSurveyLinkContainer").css({border:"1px solid #FFFFFF",background:"none"});
				window.clearInterval(windowEvent.timer);
			});

		},
		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"});
				$(pImageId).attr("src", HEADER_ARROW_OVER);
				$("#logoContainer").animate({opacity:1},100, function() {
					$(pDropdownId).slideDown(pSpeed);
				});
			}
			else {
				$(pDropdownId).slideUp(pSpeed);
				$("#logoContainer").animate({opacity:1},(pSpeed + 100), function() {
					$(pImageId).attr("src", HEADER_ARROW_OFF);
					$(pLinkId).css({border:"1px solid #FFFFFF",background:"none"});
				});
			}
		});
	}
	
	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 headerBindSurvey() {
		
		$("#entranceSurveyFormContainer").mouseover(function() {
	        window.clearInterval(windowEvent.timer);
	    });
		
		$("#closeSurvey").click(function(){
			$("#entranceSurveyFormContainer").slideUp(1000);
			$("#logoContainer").animate({opacity:1},1100, function() {
				$("#entranceSurveyImage").attr("src", HEADER_ARROW_OFF);
				$("#entranceSurveyLinkContainer").css({border:"1px solid #FFFFFF",background:"none"});
			});
		});
		
		$("#submitGlobalSurvey").click(function(){
			$("#entranceSurveyFormContainer").slideUp(1000);
			$("#logoContainer").animate({opacity:1},1100, function() {
				$("#entranceSurveyImage").attr("src", HEADER_ARROW_OFF);
				$("#entranceSurveyLinkContainer").css({border:"1px solid #FFFFFF",background:"none"});
			});
		});
		
		if (sbweb.util.cookies.getCookie("SurveyClosed") == false) {
			$("#entranceSurveyImage").attr("src", HEADER_ARROW_OVER);
			$("#entranceSurveyLinkContainer").css({border:"1px solid #ccc",background:"url(/sbweb/common/images/header/background/bg_gradient_button.gif) repeat-x top"});
			$("#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 {
		bindHeaderElements : function(pScope) {
			
			// Set position for dropdowns
			headerSetDropdownPosition("#entranceSurveyLinkContainer","#entranceSurveyFormContainer");
			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","#entranceSurveyLinkContainer","#entranceSurveyFormContainer","#entranceSurveyImage",1000);
			
			// Bind header dropdown elements
			headerBindContact();
			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");
				}
			);	
		},
	
		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 > ul").tabs("select", t);
					return(false);
				}
			);
		},
		
		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");
				}
			);
		},
		
		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;
		}
	};
}();