willow.fixPodiumNav();

willow.ready(function($) {
	// Menu data 
	var menuOptions = {currentL1:pdGlobal.currentPages[0].id};
	willow.getMenu("151918|151919|151920|151921|151922|151923|151924",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();
		}
	});
	
	// Emergency Bulletin 
	var emOptions = {emButtonPosition: "right", emButton: false};
	willow.getNews("15182",function(data){$('#Form1').bulletin(data,emOptions);},{"backlink":window.location});
	
	// Portal specific styles
	if(pdGlobal.currentPages[pdGlobal.currentPages.length-1].id === 152362){
		$("#Form1").addClass("homepage");
		/*
		// All photos from first album only, commented out function call when updated from photo group to link group.
		willow.getPhotos(46889,function(data){
			// default photo path var so only one template can be used
			var dPath = "https://cdn.media56.whipplehill.net/ftpimages/223/podium/style637/images/defaultBannerPhoto.jpg";
			if(typeof data.photo.images !== "undefined"){
				if(data.photo.images[0].path.length > 60){
					$("#bannerImgTmpl").tmpl(data.photo.images).appendTo("#bImgs");//.wrap(function(){
						$("#bImgs").cycle({ fx: 'fade', speed: 1000, timeout: 5500, pager: '#galleryNav', startingSlide: 0 });
					//});
					return;
				}
			}
			$("#bannerImgTmpl").tmpl({path:dPath}).appendTo("#bImgs");
		});*/
		
		// jQuery template self managed links
		willow.getLinks(19012,function(data){
			var links = data.link;
			if(links.length === 0){return;}
			$("#banLinksTmpl").tmpl(links,{
				target : willow.checkTarget,
				img : willow.checkImg
			}).appendTo("#bImgs");
			$("#bImgs").cycle({ fx: 'fade', speed: 1000, timeout: 5500, pager: '#galleryNav', startingSlide: 0 });
		});
	}
	
	(pdGlobal.currentPages[pdGlobal.currentPages.length-1].type === "content") ? $("#lInTblLCell").addClass("hideEl") : $("#Form1").addClass("nonContent");

	// Breadcrumb trail
	$("#breadcrumbTmpl").tmpl(pdGlobal.currentPages,{
		curID : pdGlobal.currentPages[pdGlobal.currentPages.length-1].id
	}).appendTo("#breadcrumb");
	
	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 left col
	if($curPg === 204 || $curPg === 52416 || $curPg === 6658 || $curPg === 52563){
		$("#lInTblLCell").addClass("hideEl");
	}
});

// 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;
}
