willow.fixPodiumNav();

switch(pdGlobal.currentPages[0].id){
	case 126536: bannerPhotoID = 28809; meetLinkID = 15571; break; // About Us
	case 126586: bannerPhotoID = 28810; meetLinkID = 15753; break; // Admissions
	case 126605: bannerPhotoID = 28811; meetLinkID = 15754; break; // Academics
	case 126708: bannerPhotoID = 28812; meetLinkID = 15755; break; // Athletics
	case 126728: bannerPhotoID = 28813; meetLinkID = 15756; break; // Arts
	case 127010: bannerPhotoID = 28814; meetLinkID = 15757; break; // Campus Life
	case 126751: bannerPhotoID = 28815; meetLinkID = 15758; break; // Giving
	case 126769: bannerPhotoID = 28816; meetLinkID = 15759; break; // Summer
	default: bannerPhotoID = 28818; meetLinkID = 0; break; // Portal/Application pages
}

willow.ready(function($) {
	// Menu data 
	willow.getMenu("126536|126586|126605|126708|126728|127010|126751|126769",function(data){
		$('#L1').menu(data.menu,{showL3s:false, currentL1:pdGlobal.currentPages[0].id});
	});
	$('#search').pdSearch({showButton:true, showButtonClass:'searchButton', showButtonText:''});// Podium Search 
	$("#Form1").bulletin({data:[{type:"news",id:12674}]});// EM bulletin

	// Input year into footer so it auto updates
	$("#copyright span").html(new Date().getFullYear());

	// Add L1 page title above school nav
	if(typeof(pdGlobal.currentPages[0]) !== "undefined"){
		$(".shdr").after("<div id='navTitle'><span>"+pdGlobal.currentPages[0].title+"</span></div>");
	}
	
	var curPage = pdGlobal.currentPages[pdGlobal.currentPages.length-1],
		$inTbl = $("#lInTbl"),
		archPg = 0;
		
	// Loop through list group to get page IDs of pages to hide green sidebar
	willow.getList(5061,function(data){
		for(var i = 0; i < data.list.length; i++){
			if(parseInt(willow.striphtml(data.list[i].brief)) === curPage.id){
				willow.removeSidebar($inTbl);
			}
		}
	});
	// Hide sidebar on portal, application, news/event detail pages
	if(curPage.type === "portal" || curPage.type === "application" || curPage.id === 204 || curPage.id === 52416){
		willow.removeSidebar($inTbl);
	}
	// Hide sidebar on archive pages
	for(var j = 0; j < pdGlobal.currentPages.length; j++){
		if(pdGlobal.currentPages[j].id === curPage.id){
			archPg += 1;
		}
		if(archPg === 2){
			willow.removeSidebar($inTbl);
		}
	}
	
	if(meetLinkID !== 0){
		// left column "Meet Greenhill" boxes added by jQuery template
		willow.getLinks(meetLinkID,function(data){
			$("#meetGreenTmpl").tmpl(data.link).appendTo("#meetGreenhill");
		});
	}
	
	// Breadcrumb trail added by jQuery template
	$("#breadcrumbTmpl").tmpl(pdGlobal.currentPages).appendTo(".breadcrumb");

	// Accordion links for blog
	if($(".accordion").length > 0){
		// Uses jGFeed plugin to pass RSS feed through Google's feed API which converts data to JSON
		$.jGFeed('https://greenhillintheclassroom.com/feed/',function(feeds){
			var acordOpts = {header:".aHead", clearStyle:true};
			if(!feeds){return}
			// Added by jQuery template
			$("#accordionTmpl").tmpl(feeds.entries).appendTo(".accordion").wrap(function(){
				$(".accordion").accordion(acordOpts); // using callback of wrap function to execute the accordion function once all the data is on the page
				$(".aHead span").fsplit(25);
			});
		},3);
	}

	// Accordion links for Alumni blog
	if($(".accordion2").length > 0){
		// Uses jGFeed plugin to pass RSS feed through Google's feed API which converts data to JSON
		$.jGFeed('http://greenhillalumniblog.com/feed/',function(feeds){
			var acordOpts = {header:".aHead", clearStyle:true};
			if(!feeds){return}
			// Added by jQuery template
			$("#accordionTmpl").tmpl(feeds.entries).appendTo(".accordion2").wrap(function(){
				$(".accordion2").accordion(acordOpts); // using callback of wrap function to execute the accordion function once all the data is on the page
				$(".aHead span").fsplit(25);
			});
		},3);
	}
	
	//Was adding space below footer
	$("img[name*='s_i_whipgreenhill']").css("display","none");
	
	// Meet greenhill banner changes
	if(pdGlobal.currentPages[0].id === 126848){
		$("#lOutTblLCell").addClass("meetGreenhill");
		$("#bannerPhotos").css("display","none");
	}
	else{
		// banner photos added by jQuery template
		willow.getPhotos(bannerPhotoID,function(data){
			// default photo path var so only one template can be used
			var dPath = {path:"/ftpimages/136/podium/Style546/images/defaultBannerPhoto.jpg"};
			if(typeof data.photo.images === "undefined"){
				$("#bannerImgTmpl").tmpl(dPath).appendTo("#bannerPhotos");
			}else{
				// Check to see if there are photos added to the album if not show default photo
				if(data.photo.images[0].path.length > 22){
					for(var i = 0; i < data.photo.images.length; i++){
						var IDs = data.photo.images[i].cap.split(",");
						for(var j = 0; j < IDs.length; j++){
							if(parseInt(IDs[j]) === pdGlobal.currentPages[pdGlobal.currentPages.length-1].id){
								$("#bannerImgTmpl").tmpl(data.photo.images[i]).appendTo("#bannerPhotos");
							}
						}
					}
					if($("#bannerPhotos").children().length < 1){
						$("#bannerImgTmpl").tmpl(data.photo.images).appendTo("#bannerPhotos");
					}
					$("#bannerPhotos").cycle();
				}else{$("#bannerImgTmpl").tmpl(dPath).appendTo("#bannerPhotos");}
			}		
		});
	}

	setTimeout("delay()",1);
});

willow.removeSidebar = function($obj){
	$obj.addClass("no_sidebar");
}

// Fixes footer for IE and Apple products
function delay(){
	if($.browser.msie){
		$("#stickyFooter").addClass("iePosition");
		$("#stickyFooter").css("top",$(window).height()-37+"px");
		
		$(window).resize(function(){
			$("#stickyFooter").css("top",$(window).height()-37+"px");
		});
		$(window).scroll(function(){ 
			$("#stickyFooter").css("top",$(window).scrollTop()+$(window).height()-37+"px");
		});
	}
}
