function fadePromo() {
		if (currentPromo == totalPromos) {
			var nextPromo = 0;
			var prevPromo = currentPromo - 1;
		} else if (currentPromo == 0) {
			var nextPromo = currentPromo + 1;
			var prevPromo = totalPromos;
		} else {
			var nextPromo = currentPromo + 1;
			var prevPromo = currentPromo - 1;
		}
		/*
		alert(currentPromo);
		alert(totalPromos);
		alert(nextPromo);
		alert(prevPromo);
		*/
		$(this).oneTime (6000, function() {
			if (startAnimation == 1) {
				$('#homeRotatingFeature img:eq(' + currentPromo + ')').fadeOut(2000);
				$('#homeRotatingFeature img:eq(' + nextPromo + ')').fadeIn(2000);
				currentPromo = nextPromo;
				fadePromo ();
			}
		});
}

$(document).ready(function()
	{
		// Toggle ministry menu when button is clicked
		$('#ministry_menu_button').click(function()
			{
				if ($('#ministry_menu').is(':hidden'))
				{
					$(this).addClass('alt');
					$('#ministry_menu').fadeIn('fast');
					this.blur();
					return false;
				}
				else
				{
					$(this).removeClass('alt');
					$('#ministry_menu').fadeOut('fast');
					this.blur();
					return false;
				}
			}
		);

		// Clicking the body should close menu
		$('body').click(function()
			{
				if ($('#ministry_menu').is(':visible'))
				{
					$('#ministry_menu').fadeOut('fast');
					$('#ministry_menu_button').removeClass('alt');
				}
			}
		);

		// Clicking the menu shouldn't close it
		$('#ministry_menu').click(function()
			{
				return false;
			}
		);
		
		$('#ministry_menu a').click(function()
			{
				window.location = $(this).attr('href');
			}
		);

		// Define global variable NATHANSMITHsearchText for portability
		// Used name in all-caps as pseudo-namespace to avoid collision
		window.NATHANSMITHsearchText = $('#header label').text();

		// Add instructional text to the search field
		$('#search_field')[0].value = NATHANSMITHsearchText;

		// Clear search field when focused
		$('#search_field').focus(function()
			{
				if ($('#search_field')[0].value === NATHANSMITHsearchText)
				{
					$('#search_field')[0].value = '';
				}
			}
		);

		// Replace phrase if search unused
		$('#search_field').blur(function()
			{
				if ($('#search_field')[0].value === '')
				{
					$('#search_field')[0].value = NATHANSMITHsearchText;
				}
			}
		);

		// If no text entered, do not submit
		$('#header form').submit(function()
			{
				if ($('#search_field')[0].value === '' || $('#search_field')[0].value === NATHANSMITHsearchText)
				{
					return false;
				}
			}
		);

		// Display sub-nav on delayed hover
		$('#sub_49_trigger').hoverIntent(function()
			{
				$('#header li').removeClass('alt');
				$(this).parent('li').addClass('alt');
				$('.sub_nav').removeClass('alt').hide();
				$('#sub_nav_49').show();
			},
			function()
			{
				//
			}
		);
		$('#sub_48_trigger').hoverIntent(function()
			{
				$('#header li').removeClass('alt');
				$(this).parent('li').addClass('alt');
				$('.sub_nav').removeClass('alt').hide();
				$('#sub_nav_48').show();
			},
			function()
			{
				//
			}
		);
		$('#sub_47_trigger').hoverIntent(function()
			{
				$('#header li').removeClass('alt');
				$(this).parent('li').addClass('alt');
				$('.sub_nav').removeClass('alt').hide();
				$('#sub_nav_47').show();
			},
			function()
			{
				//
			}
		);
		$('#sub_46_trigger').hoverIntent(function()
			{
				$('#header li').removeClass('alt');
				$(this).parent('li').addClass('alt');
				$('.sub_nav').removeClass('alt').hide();
				$('#sub_nav_46').show();
			},
			function()
			{
				//
			}
		);
		$('#sub_45_trigger').hoverIntent(function()
			{
				$('#header li').removeClass('alt');
				$(this).parent('li').addClass('alt');
				$('.sub_nav').removeClass('alt').hide();
				$('#sub_nav_45').show();
			},
			function()
			{
				//
			}
		);
		$('#sub_44_trigger').hoverIntent(function()
			{
				$('#header li').removeClass('alt');
				$(this).parent('li').addClass('alt');
				$('.sub_nav').removeClass('alt').hide();
				$('#sub_nav_44').show();
			},
			function()
			{
				//
			}
		);
		
		// Sermon Lists
		$('table.recent_sermons tbody tr:even').addClass('odd');
		$('table.sermon_series:even').addClass('odd');
		$('table.sermon_series').wrap('<div class="series_container collapsed"></div>')
		$('table.sermon_series').bind('click', function () {
			$(this).parent().toggleClass ('collapsed');
			});
			
		
		// Home Page Fading Features 7/09
		startAnimation = 1;
		totalPromos = $('#homeRotatingFeature img').size();
		totalPromos = totalPromos - 1
		currentPromo = 0;
		
		$('#homeRotatingFeature img:gt(0)').hide();
		fadePromo();
	
		$('#prevFeature').bind('click', function () {
			startAnimation = 0;
			$('#homeRotatingFeature img').fadeOut(1000);
			if (currentPromo == totalPromos) {
				var nextPromo = 0;
				var prevPromo = currentPromo - 1;
			} else if (currentPromo == 0) {
				var nextPromo = currentPromo + 1;
				var prevPromo = totalPromos;
			} else {
				var nextPromo = currentPromo + 1;
				var prevPromo = currentPromo - 1;
			}
			$('#homeRotatingFeature img:eq(' + prevPromo + ')').fadeIn(1000);
			currentPromo = prevPromo;
		});
		
		$('#nextFeature').bind('click', function () {
			startAnimation = 0;
			$('#homeRotatingFeature img').fadeOut(1000);
			if (currentPromo == totalPromos) {
				var nextPromo = 0;
				var prevPromo = currentPromo - 1;
			} else if (currentPromo == 0) {
				var nextPromo = currentPromo + 1;
				var prevPromo = totalPromos;
			} else {
				var nextPromo = currentPromo + 1;
				var prevPromo = currentPromo - 1;
			}
			$('#homeRotatingFeature img:eq(' + nextPromo + ')').fadeIn(1000);
			currentPromo = nextPromo;
		});
		
		$('#memberButton').bind('click', function () {
			$('#visitorButton').removeClass('active');
			$(this).addClass('active');
			$('#visitorList').hide();
			$('#memberList').show();
		});
		
		$('#visitorButton').bind('click', function () {
			$('#memberButton').removeClass('active');
			$(this).addClass('active');
			$('#memberList').hide();
			$('#visitorList').show();
		});
		
				
	}
);

