willow.fixPodiumNav();

willow.ready(function($) {
	// Menu data 
	var menuOptions = {direction:"down", showL3s:false, currentL1:pdGlobal.currentPages[0].id};
	willow.getMenu("134981|134982|134983|134984|134985|134986|134987",function(data){
		$('#L1').menu(data.menu,menuOptions);
	});
	
	// Podium Search 
	$('#search').pdSearch({showButton:true, showButtonClass:'searchButton', showButtonText:''}); 
	$(".searchButton").css("margin","0");
	
	// Emergency Bulletin 
	var emOptions = {emButtonPosition: "right", emButton: false};
	willow.getNews("12369",function(data){$('#Form1').bulletin(data,emOptions);},{"backlink":window.location});
	
	// Homepage specific styles, see banner.css
	if(pdGlobal.currentPages[pdGlobal.currentPages.length-1].id === 134980){
		$("#Form1").addClass("homepage");
		
		$("#L1_134981").attr("hoffset","-29");
		$("#L1_134982").attr("hoffset","-37");
		$("#L1_134983").attr("hoffset","-40");
		$("#L1_134984").attr("hoffset","-41");
		$("#L1_134985").attr("hoffset","-21");
		$("#L1_134986").attr("hoffset","-54");
		$("#L1_134201").attr("hoffset","-55");
	}
	// jQuery template self managed links
	// jQuery template self managed links
	willow.getLinks(14378,function(data){
		var links = data.link;
		if(links.length === 0){return;}
		$("#linksTemplate").tmpl(links,{
			target : willow.checkTarget,
			img : willow.checkImg
		}).appendTo("#socialMedia");
	});
});

mStyle({
	contentAreaBackgroundAlpha : 0
}).makeVar();

// Checks to see if self managed link has the 'open in new tab' flag set 
willow.checkTarget = function(target){
	if(target === 1 || target === true || target === "true"){
		return " target='_blank'";
	}
	return "";
};

// Checks to see if self managed link has an image
willow.checkImg = function(link){
	if(typeof link.data.image !== "undefined"){
		if(link.data.image.height > 0 && link.data.image.width > 0){
			return "<img src='https://cdn.media910.whipplehill.net"+link.data.image.path+"' height='"+link.data.image.height+"' width='"+link.data.image.width+"' alt='"+link.data.title+"' border='0'/>"
		}else{
			return "<img src='https://cdn.media910.whipplehill.net"+link.data.image.path+"' alt='"+link.data.title+"' border='0'/>"
		}
	}
	return link.data.title;
}
