
$(function(){
	
	// header links
	$('#header > ul > li').each( function () {
		var $this = $(this),
			l = $('>a', $this),
			m = $('>dl', $this).add( $('>a span',$this) ).hide();
		
		$this
			.hover( function() {
				m.fadeTo(90, 1).css('display','block').fadeTo(10,1);
			}, function() {
				m.fadeTo(400, 0, function(){m.hide();});
			});
		
		$this.parent().removeClass('nojs');
	});
	
	// label fading
	$('.label-holder').each( function () {
		var $this = $(this),
			label = $('label', $this),
			form  = $('input[name="'+label.attr('for')+'"]', $this),
			input = form.get(0);
		
		// don't operate on a null label
		if (!input)
			form = $('textarea[name="'+label.attr('for')+'"]', $this);
		if (!form) 
			return;
		else
			input = form.get(0); 
		
		form
			.bind('focus', function() {
				if (input.value == '')
					label.stop().show().fadeTo(200, .3);
				else
					label.hide();
			})
			.bind('blur', function() {
				if (input.value == '')
					label.stop().show().fadeTo(400, 1);
				else
					label.hide();
			})
			.bind('keydown', function(e) {
				if ( (e.keyCode == 8 || e.keyCode == 46) && input.value.length <= 1)
					label.stop().show().fadeTo(400, .3);
				else 
					label.hide();
			});
		label
			.bind('click', function() {
				if (input) input.focus();
			});

		if (input && input.value != '') {
			label.hide();
		}
	});
	
	
});