willow.ready(function($) {
	if(hasflash !== 1){// If no flash 
		$(".newsTitle").fsplit(45); // Limit length of news titles and event titles
		$(".newsBrief").fsplit(65);
		$(".eventTitle").fsplit(25);
		// controls news/event stories slide
		willow.slideContent();
	}
	
	willow.getMenu("138723|138724|138725|138767|138726",function(data){// Menu data 
		$('#L1').menu(data.menu,{showL3s:false,speed:0});
	});
	
	// EM bulletin
	var emOptions = {emButtonPosition: "right",emButton: false};
	willow.getNews("14813",function(data){$('#Form1').bulletin(data,emOptions);$("#emDetail").fsplit(175);},{"backlink":window.location});
	//Was adding space below footer
	$("img[name*='s_i_whiprippowam']").css("display","none");
	
	var $tabs = $(".tab");
	$tabs.click(function(e){
		if(!$(this).hasClass("off")){return;} // Prevents switch when clicking current tab that's on
		e.preventDefault();
		$tabs.toggleClass("off");
		$(".newsEvents").toggleClass("showing");
	});
	
	var $window = $(window);
	$("#non_flash_content").width($window.width() - 192); // Resizes flash container so image doesn't go behind right bar
	$window.resize(function(){ 
		$("#non_flash_content").width($window.width() - 192);
	});
	
	$("#news").css("display","block");
	$("#events").css("display","block");
});

willow.slideContent = function(){
	var nHeight = 135, // Height of news item
		eHeight = 40, // Height of events item
		animateRunning = false, // variable to keep track of if animation is running
		h = 0; // height to slide content
			
	// Set position of stories
	willow.setPosition($(".story"),nHeight);
	willow.setPosition($(".singleEvent"),eHeight);
	
	// Up arrow click
	$(".upClick").click(function(e){
		e.preventDefault();
		var $objs = $(this).siblings("ul").find("li");
		($objs.eq(0).hasClass("story")) ? h=nHeight : h=eHeight;
		if($objs.eq(0).css("top") !== "0px"){ // check to make sure cannot scroll first item down if at top
			if(!animateRunning){ // check to make sure animation doesnt overlap each other
				animateRunning = true;
				$objs.each(function(){ // move each story down the specific height
					var a = $(this).position().top + h;
					$(this).animate({"top": a+"px"},function(){ // run animation
						animateRunning = false; // reset animation tracking variable
					});	
				});
			}
		}
	});
	
	// Down arrow click
	$(".downClick").click(function(e){
		e.preventDefault();
		var $objs = $(this).siblings("ul").find("li");
		($objs.eq(0).hasClass("story")) ? h=nHeight : h=eHeight;
		if($objs.eq($objs.length - 1).css("top") !== ("0px")){ // check to make sure click does not happen if last item is showing at the top
			if(!animateRunning){ // check to make sure animation doesnt overlap each other
				animateRunning = true;
				$objs.each(function(){ // move each story up the specific height
					var a = $(this).position().top - h;
					$(this).animate({"top": a+"px"},function(){
						animateRunning = false; // reset animation tracking variable
					});
				});
			}
		}
	});
}

// Set position function, height of container plus height of margin
willow.setPosition = function($obj,h){
	$obj.css("top", function(i,v){
		return (i*h)+"px";
	});
}
