$(document).ready(function()
	{		
		
		// Show/hide sub-menus, context-sensitive for current sub-menus
		$('#header li:has(ul)')
		.mouseover(function()
			{
				$(this).addClass("hover");
				$('#header li ul').hide();
				$('#header li.hover ul').show();
			}
		)
		.mouseout(function()
			{
				$(this).removeClass("hover");
				$('#header li ul').hide();
				$('#header li.current ul').show();
			}
		);
		
		
		// Make sure our top-level menu stays highlighted when we're browsing its sub-menu
		$('#header li ul')
		.mouseover(function()
			{
				$(this).parent().addClass("hover");
			}
		)
		.mouseout(function()
			{
				$(this).parent().removeClass("hover");
			}
		);
		
		
		// auto-populate some form fields with their titles
		$('.populate').each(function(){
	
			var e = $(this);
			if (!e.val()) {
				e.val(e.attr('title'));
			 }
		
			e.focus(function(){
			  var e = $(this);
			  if (e.attr('title') == e.val()) {
				e.val('');
			  }
			});
			
			e.blur(function(){
			  var e = $(this);
			  if (!e.val()) {
				e.val(e.attr('title'));
			  }
			});
		});
		
		
		// Dismiss alerts
		$('a.dismiss').show();
		$('a.dismiss').click(function()
		{
			$(this).parent().fadeOut('slow');
			return false;
		});
		
		
		// Form to update entries
		$('div#updateForm').hide();
		$('td.updated a').click(function()
		{
			$('div#updateForm').slideToggle();
			return false;
		});
		
		
		// FAQ jiggery
		$('ul.faqs div.faqAnswer').hide();
		$('ul.faqs div.faqSummary').show();
		$('ul.faqs a.toggle').show();
		
		$('ul.faqs a.toggle').click(function()
			{
				var context = $(this).parents('li.faq');
				$('div.faqSummary', context).toggle();
				$('div.faqAnswer', context).toggle();
				
				if ( $(this).text() == "(more)" ) {
					$(this).text("(less)");
				} else {
					$(this).text("(more)");
				}
				return false;
			});
		
		
		// Hide child category lists in the sidebar
		$('#sidebar ul.filter li ul').hide();
		
		
		// Then make them show/hide on click
		$('#sidebar ul.filter li:has(ul) a:first').click(function()
		{
			var me = $(this).parent();
			me.toggleClass("current");
			$('ul', me).slideToggle();
			return false;
		});
	
		
		
	}
);
