
$(document).ready(function(){
	
	/* let the CSS know that we have JS */
	
	$('body').addClass('jsyes');
	
	/* Make the "skip" link actually give the nav focus */
	
	$('#skiplink').focus(function(){ $(this).css({left:0}) });
	
	$('#skiplink').blur(function(){ $(this).css({left:'-1000px'}) });
	
	$('#skiplink').click(function(){ $('#siteTitle a').focus(); });
	
	/* Set up the gallery arrows */
	
	$('#content p.attachment img').load(function(){
		var h = $(this).height();
		$('.single-attachment #content div#nav-below a').css({top:(h/2-23)}).fadeIn('slow');
	});
	
	/* Hide/Show the default value when users click a text field */
	
	$('form input[type="text"]:not(#s), form input[type="password"]').focus(function(){
	  var input = $(this);
	  if ( !input.data('default') ) { input.data('default', input.val()) };
	  if ( input.val() === input.data('default') ) { input.val(''); }
	}).blur(function(){
	  var input = $(this);
	  if ( input.val() === '' ) { input.val(input.data('default')) };
	});
	
	/* Search Form */

	$('#search label').click(function(){
		showSearch();
	});
	
	$('#search input').blur(function(){
		// alert($('#search input[type=text]').text());
		if ( $('#search input[type=text]').val() === '' ) {
			hideSearch();
		} else return;
	});

	/* Drop Down Hover */
	
	$('.dropdown dt a').click(function(){
		var which = $(this).closest('dl');
		$('dd',which).slideToggle('medium',function(){
			which.toggleClass('open');
		});
		return false;
	});
	
	/* Drop Down Click*/
	
	$('.expandable dt a').click(function(){
		var which = $(this).closest('dl');
		$('dd',which).slideToggle('medium',function(){
			which.toggleClass('open');
		});
		return false;
	});
	
	$('.single-attachment #content div#nav-below a img').each(function(){
		if(this.complete) $(this).load();
	});
	
	/* The Sounds */
	
	$('#aboutSounds').slideUp(0);
	$('#aboutSounds .info-wrap').css({opacity:0});
	
	$('#soundsInfo').click(function(){
		$(this).fadeOut('slow');
		$('#aboutSounds').slideDown('slow',function(){
			$('#aboutSounds .info-wrap').animate({opacity:1},'slow');
		});
		return false;
	});
	
	$('#aboutSounds a.close').click(function(){
		$('#aboutSounds .info-wrap').animate({opacity:0},'slow',function(){
			$('#aboutSounds').slideUp('slow',function(){
				$('#soundsInfo').fadeIn('slow');
			});
		});
		return false;
	});
	
});

function showSearch(){
	$('#search').addClass('on');
	$('#search label').hide();
	$('#search input[type=text]').focus();
}

function hideSearch(){
	$('#search').removeClass('on');
	$('#search label').show();
}
