willow.ready(function($){
	/* Emergency Bulletin */
	var emOptions = {emButtonPosition: "right",emButton: false};
	willow.getNews("12548",function(data){$('#Form1').bulletin(data,emOptions);},{"backlink":window.location});
	
	/* Menu data */
	var menuOptions = {direction:"down", showL3s:false};
	willow.getMenu("124921|124922|124923|124926|124927|124928|124929",function(data){
		$('#L1').menu(data.menu,menuOptions);
	});
	
	/* Podium Search */
	$('#search').pdSearch({showButton:true, showButtonClass:'searchButton', showButtonText:''}); 
	$(".searchButton").css("margin","0");
	
	/* Cycle main photos using the cycle plugin */
	$(".photos").cycle({timeout:6000});
	
	/* Cut the news detail length at 280 characters */
	$(".newsDetail").fsplit(280);
	
	/* Story pager functionality */
	willow.storyPager();
	
	/* Slides down the news and events boxes */ 
	willow.showContent($(".header"));
	
	$(".eventDetail").fsplit(90);
});	

willow.showContent = function($clickObj){
	/* Toggles between clicks to either show or hide */
	$clickObj.toggle(
		function(){
			$(this).children().last().attr("src","/images/closeBtn.png"); // Change the +/- image in the upper right of the header 
			$(this).siblings().children().css("height","202px").animate({"top":0}); // Give the content some height to push the footer down and animate down
		},
		function(){
			$(this).children().last().attr("src","/images/openBtn.png"); // Change the +/- image in the upper right of the header 
			$(this).siblings().children().animate({"top":-239},function(){ // Animate content up
				$(this).css("height","0");	// Remove the content height to push footer up
			});
		}
	);
}

willow.storyPager = function(){
	/* Display first story */
	$("#story_0").fadeIn();
	$("#pager_0").addClass("on");

	/* Binds click event to each pager number */
	$("#numStories span").click(function(){
		var pNum = $(this).attr("id").split("_"); /* Get pager index */
		$("#numStories span").removeClass("on"); /* Removes all on states of pagers */ 
		$(this).addClass("on"); /* Turns on clicked pager on state*/ 

		/* Loop through each story */
		for(var i = 0; i < $(".story").length; i++){
			/* If the showing story is not the pager index clicked hide the showing story and show the new story */
			if(i != pNum[1]){ 
				if($(".story").eq(i).css("display") === "block"){
					$(".story").eq(i).fadeOut();
				}
			}
			else{
				$(".story").eq(pNum[1]).fadeIn();
			}
		}
	});
}
