willow.fixPodiumNav();

willow.ready(function($) {
	$("#Form1").bulletin({data:[{type:"news",id:12675}]});// EM bulletin
	$('#search').pdSearch({showButton:true, showButtonClass:'searchBtn', showButtonText:''}); // Podium Search 
	
	if(pdGlobal.currentPages[pdGlobal.currentPages.length-1].type !== "content"){ // Show background if not a content page
		$("body").addClass("nonContent");
	}
	if(pdGlobal.currentPages[pdGlobal.currentPages.length-1].id === 140295){ // Homepage only styles
		$("body").addClass("homepage");
		
		willow.getNews(12776,function(data){
			if(data.news[0].image.path.length > 60){
				$("#hpVideoThumbTmpl").tmpl(data.news[0].image).appendTo("#hpVideoThumb");
			}
		});
		
		$("#hpVideoThumb").removeClass("hideEl").click(function(e){ // On click of video thumb hide it and show video
			e.preventDefault();
			$(this).addClass("hideEl");
			$("#hpVideo").removeClass("hideEl");
			
			willow.getNewsMedia(12776,function(data){ // Get video for homepage
				if(data.news.length > 0){
					if(data.news[0].media.length > 0){
						$("#hpVideoTmpl").tmpl(data.news[0].media[0]).appendTo("#hpVideo").wrap(function(){
							brightcove.createExperiences();
						});
					}
				}
			});
		});
	}
	
	willow.getMenu("139879|139880|139881|139882|139883",function(data){// Menu data 
		for(var i = 0; i < data.menu.length; i++){
			if(data.menu[i].id === pdGlobal.currentPages[0].id){
				$("#L1_"+pdGlobal.currentPages[0].id).addClass("on");
			}
			$("#L2menuTmpl").tmpl(data.menu[i].L2,{ // Build out L2 menu items
				pageL2 : function(){if(pdGlobal.currentPages.length > 1){return pdGlobal.currentPages[1].id;}}
			}).appendTo("#L2_"+data.menu[i].id).wrap(function(){
				if($.browser.msie){$(".L2 li a").last().css("border","0");} // Need to remove border from last L2 item in IE, IE doesn't support css pseudo-class :last-child
			});
		}
	});

	$(".liL1").hover(function(){
		$(this).children(".aL1").toggleClass("hover");
		$(this).children(".L2").toggleClass("hideEl");
		$("#L1_"+pdGlobal.currentPages[0].id).toggleClass("on");
	});
	
	// jQuery template self managed links
	willow.getLinks(15101,function(data){
		var links = data.link;
		if(links.length === 0){return;}
		$("#linksTmpl").tmpl(links,{
			target : willow.checkTarget,
			img : willow.checkImg
		}).appendTo("#socialMedia");
	});
	
	if($(".annualFund").length > 0){$(".annualFund").annualfund("",{bar_height:101});}// Annual fund
});

// 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;
}
