willow.ready(function($){

		//emergency bulletin
		$('#Form1').bulletin({emButton: false, data:[{type:"news",id:9250}]});
		
		//menu
		willow.getMenu("49731|49771|49753|49790|49823|105669",function(data){
			$("#L1").menu(data.menu,{showL3s: false});
		});
		//search
		$('#search').pdSearch({showButton:true, showButtonClass:'searchSubmit',showButtonText:''});
		//photo slider 
		$('#photos').anythingSlider({
			hashTags: false,
			buildArrows: false,
			buildNavigation:true,
			navigationFormatter: function(index, panel){
				var thisImage = panel.children(".mainPhoto").attr("src");
				thisImage = "<img src='"+thisImage+"'/>";
				return thisImage; //returning an image inside the pager <a> tag, so we can show the image on hover for that item
			},
			autoPlay: true,	
			delay: 5000,
			animationTime: 800,
			// Callback when the plugin finished initializing
			//this code adds the swipe functionality, so a user can click and drag or swipe with finger to move slider
			onInitialized: function(e, slider) {
				var time = 1000, // allow movement if < 1000 ms (1 sec)
					range = 20,  // swipe movement of 20 pixels triggers the slider
					x, t, r = 0,					
					st = 'mousedown', //starting at the mousedown event
					en = 'mouseup';	//ending at the mouseup event
				var touch = "ontouchend" in document;
				if (touch){ //if a touch device, using the touchwipe plugin to recognize the swipe of the slider and then call the slider function for forward or back
					slider.$window.touchwipe({
						wipeLeft: function(){slider.goForward();},
						wipeRight: function(){slider.goBack();}
					})
				}else{ //this code is so we can have a swipe like function on a computer
					slider.$window
						.bind(st, function(e){
							// prevent image drag (Firefox)
							//e.preventDefault(); //commented out so the title links will work
							t = e.timeStamp;
							x = e.pageX;
						})
						.bind(en, function(e){
							//e.preventDefault(); //commented out so the title links will work
							r = Math.abs(e.pageX - x);
							// allow if movement < 1 sec
							if (e.timeStamp - t < time) {
								if (e.pageX < x && r > range) {
									slider.goForward();
								}
								if (e.pageX > x && r > range) {
									slider.goBack();								
								}
							}
						});
				}
			}

		});
		//removing the title attribute from the <a> tag in the slider pager, so the image HTML doesn't appear in the tooltip on hover over the pager
		setTimeout("$('.photoArea .thumbNav li a').removeAttr('title');",1000);
		//news pager
		$(".news").anythingSlider({
			hashTags: false
		});
		$(".news .newsBrief").fSplit({maxChar:210,stripHTML:false});
		$(".news .newsBrief").each(function(){
			var newsHeight =$(this).height();
			if(newsHeight > 144){
				var heightDiff = newsHeight - 144;
				heightDiff = Math.floor(heightDiff/18);				
				var reduceChar = heightDiff * 40;
				var maxCharacters = 210-reduceChar;
				$(this).fSplit({maxChar:maxCharacters, stripHTML: false});
			}
		});
});	
function getNewsHeight(){				
	while ($(".news_list").height()>158)
	{$(".newsItem_"+lastStory).css("display","none");lastStory--;}
}	
