$(document).ready(function()
{
	$('.loading').hide();
	$('div.gallery img').each(function(){
		$(this).click(function(ev){
			ev.preventDefault();
			var id_arr = $(this).attr('id').split('_');
			var id=id_arr[1];
			
			$('.large_image').fadeOut('slow',function(){
				$('.loading').show();
				$('.large_image').load("/ajax/show_image/"+id+"/leader_picture",function(){
					$('.large_image img').load(function(){
						$('.loading').hide();
						$('.large_image').fadeIn('slow');
					});
				});
			});
		});
	});
	
	// Slideshow...
	$('#slides').before('<ul id=slideshowNav></ul>').cycle({
		fx:      'fade',
		pager:   '#slideshowNav',
		timeout:  6000,
		pagerAnchorBuilder: function(idx, slide) {
			return '<li><a href="#">'+(idx+1)+'</a></li>';
		}
	});

	// Nav hover...
	$('#navigation ul li').hover(function(){
		$(this).find('ul').show().find('ul').hide();
	},function(){
		$(this).find('ul').hide().find('ul').show();
	});
	
	// hide the text in the search bar
	$('#q').each(function()
	{
		document['def_'+$(this).attr('name')] = $(this).attr('value');
		$(this).focus(function()
		{
			if($(this).attr('value') == document['def_'+$(this).attr('name')]) $(this).attr('value','');
		});
		$(this).blur(function()
		{
			if($(this).attr('value') == '') $(this).attr('value',document['def_'+$(this).attr('name')]);
		});
	});

	if(news_page == true) {
		$('.news_archive .pad10 hr:first').after('<p><a href="/news">Recent News</a></p><hr/>');
	}
	
  $('a.new-window').click(function(){
  	window.open(this.href);
    return false;
  });

})
