willow.fixPodiumNav();

willow.ready(function($) {
	// Emergency Bulletin
	willow.getNews("12539",function(data){$('body').bulletin(data,{emButton: false});},{"backlink":window.location});
	
	// Menu data 
	var menuOptions = {showL3s:false, currentL1:pdGlobal.currentPages[0].id};
	willow.getMenu("135342|135343|135344|137869|135345|135346|135348|139179",function(data){
		$('#L1').menu(data.menu,menuOptions);
		
		var $sitemap = $(".sitemap");
		if($sitemap.length > 0){
			$sitemap.sitemap(data);
			//uncomment this if you want to expand all by default $("#expand").click();
		}
		// Adding Footer sitemap via jQuery Template
		$("#footNavTmpl").tmpl(data.menu).prependTo("#footerNav");
	});
	
	$('#search').pdSearch({showButton:true, showButtonClass:'searchBtn', showButtonText:''}); 
	$(".searchBtn").css("margin","0");
	
	// Move usernav and schoolnav flyouts to the left 4 px
	$("#GL_un_-1").mouseover(function(){
		var p = $("TABLE.u2g").parent();
		var l = p.css('left');
		var nl = parseInt(l) - parseInt($('#Form1').offset().left);
		nl = nl - 4;
		p.css('left',nl);
	});
	$("#GL_c5i0_sn_-1").mouseover(function(){
		var p = $("TABLE.s3g").parent();
		var l = p.css('left');
		var nl = parseInt(l) - parseInt($('#Form1').offset().left);
		nl = nl - 4;
		p.css('left',nl);
	});
	
	// jQuery template social media links
	willow.getLinks(14736,function(data){
		var links = data.link;
		if(links.length === 0){return;}
		$("#linksTmpl").tmpl(links,{
			target : willow.checkTarget,
			img : willow.checkImg
		}).appendTo("#socialMedia");
	});
	
	// Open/close the sitemap
	$("#sitemap").click(function(){
		$(this).toggleClass("open");
		$("#footerNav").slideToggle();
	});
	
	// Homepage specific styles
	if(pdGlobal.currentPages[pdGlobal.currentPages.length-1].id === 135340){
		$("body").addClass("homepage");
	}
	
	// Annual fund
	if($(".annualFund").length > 0){$(".annualFund").annualfund();}
	
	if(pdGlobal.currentPages[pdGlobal.currentPages.length-1].type === "content"){$(".cal2grdwrap").css("width","846px");}
	
	var $curPg = pdGlobal.currentPages[pdGlobal.currentPages.length-1].id;
	
	// Edits width of detail pages for news, events, list, and annoucements so it doesn't have the overhang
	if($curPg === 204 || $curPg === 52416 || $curPg === 6658 || $curPg === 52563){
		$("#lPg").css("width","885px");
		$("#pgCol_0").css("width","865px");
	}
});

// 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;
}
