$(function () {
	$('.slider label').each(function () {
		var labelColor = '#aaa';
		var restingPosition = '5px';

		// Style the label with JS for progressive enhancement
		$(this).css({
			'color': labelColor,
			'position': 'absolute',
			'left': restingPosition,
			'display': 'inline',
			'top': '3px',
			'z-index': '99'
		});

		// Grab the input value
		var inputval = $(this).next('input, textarea').val();

		// Grab the label width, then add 5 pixels to it
		var labelwidth = $(this).width();
		var labelmove = labelwidth + 5;

		// onload, check if a field is filled out, if so, move the label out of the way
		if (inputval !== ''){
			$(this).stop().animate({'left': -1 * labelmove}, 1);
		}

		// If the input is empty on focus move the label to the left
		// If it's empty on blur, move it back
		$('input, textarea').focus(function(){
			var label = $(this).prev('label');
			var width = $(label).width();
			var adjust = width + 5;
			var value = $(this).val();

			if (value == '') {
				label.stop().animate({'left': -1 * adjust }, 'fast');
			} else {
				label.css({'left': -1 * adjust});
			}
		}).blur(function(){
			var label = $(this).prev('label');
			var value = $(this).val();

			if (value == ''){
				label.stop().animate({'left': restingPosition}, 'fast');
			}
		});
	})
});