willow.fixPodiumNav();

willow.ready(function($) {
	// Podium Search 
	$('#search').pdSearch({showButton:true, showButtonClass:'searchBtn', showButtonText:''}); 
	$(".searchBtn").css("margin","0");
	
	// Menu data 
	var menuOptions = {showL3s:false, currentL1:pdGlobal.currentPages[0].id};
	willow.getMenu("129464|129465|129466|129467|129468|129469|129470|129722",function(data){
		$('#L1').menu(data.menu,menuOptions);
	});
	
	// Emergency Bulletin
	$("#Form1").bulletin({data:[{type:"announcement",id:4024}],"backlink":window.location});
	
	// jQuery template self managed links, social media links
	willow.getLinks(16198,function(data){
		var links = data.link;
		if(links.length === 0){return;}
		$("#linksTmpl").tmpl(links,{
			target : willow.checkTarget,
			img : willow.checkImg
		}).appendTo("#socialMedia");
	});
	
	// jQuery template self managed links, footer quicklinks
	willow.getLinks(16197,function(data){
		var links = data.link;
		if(links.length === 0){return;}
		$("#footQL_Tmpl").tmpl(links,{
			target : willow.checkTarget,
			img : willow.checkImg
		}).appendTo("#footQL");
	});
	
	// jQuery template self managed links, omni links
	willow.getLinks(16341,function(data){
		var links = data.link;
		if(links.length === 0){return;}
		var lCount = -1;
		$("#omniTmpl").tmpl(links,{
			target : willow.checkTarget,
			printSpcr : function(){
							lCount++;
							if(lCount >= links.length-1){
								return false;
							}else{
								return true;
							}
						}
		}).appendTo("#omniNav");
	});
	
	willow.getText(74014,function(data){
		$("#footSEO").html(data.text[0].body.replace(/&quot;/gi, "'")).wrap(function(){
			willow.stickyFooter($("#footer").height());
		});
	});
	
	willow.getText(74767,function(data){
		$("#tagline").html(data.text[0].body.replace(/&quot;/gi, "'"));
	});
	
	$("img[name='s_i_whipwoo']").css("display","none");
	
	// HP only styles
	if(pdGlobal.currentPages[pdGlobal.currentPages.length-1].id === 129475){
		$("body").addClass("homepage");
		// willow.quickLinksSlide(809);
	// }
	// else{
		// willow.quickLinksSlide(825);
	}
	//Hide login on news detail pages.
	if(pdGlobal.currentPages[pdGlobal.currentPages.length-1].id === 204 && pdGlobal.userLoggedIn === false){
		$(".u1h").css("display","none");
	}
});

// Sticky footer function for variable height of footer
willow.stickyFooter = function(h){
	$("#footer").css({"height":h+"px", "margin-top":"-"+h+"px"});
	$("#lInTbl").css("margin-bottom",h+"px");
}
// Checks to see if self managed link has the 'open in new tab' flag set 
willow.checkTarget = function(t){
	if(t === 1 || t === true || t === "true"){
		return " target='_blank'";
	}
	return "";
};

// Checks to see if self managed link has an image
willow.checkImg = function(lk){
	if(typeof lk.data.image !== "undefined"){
		if(lk.data.image.height > 0 && lk.data.image.width > 0){
			return "<img src='"+lk.data.image.path+"' height='"+lk.data.image.height+"' width='"+lk.data.image.width+"' alt='"+lk.data.title+"' border='0'/>"
		}else{
			return "<img src='"+lk.data.image.path+"' alt='"+lk.data.title+"' border='0'/>"
		}
	}
	return lk.data.title;
}

willow.quickLinksSlide = function(d){
	$("#arrowQL").click(function(e){
		e.preventDefault();
		var t = 2000; // Animation time

		if($(this).css("left") === "0px"){ // If closed
			$("#footQL").animate({"left":0},t);
			$(this).animate({"left":d},t).addClass("open");
		}
		else{ // If open
			$("#footQL").animate({"left":-d},t);
			$(this).animate({"left":0},t).removeClass("open");
		}
	});
}
