$(document).ready(function(){

	// Handle placeholder labels

	$('label.js-placeholder').addClass('placeholder').each(function(){

		// Get the id of the input this label is associated with
		var label = $(this),
			idInput = label.attr('for'),
			initialText = $('#' + idInput).val();

		// Hide the label if the input has a value
		if (initialText.length > 0) {
			label.addClass('hidden');
		}

		// Handle classes
		$('#' + idInput)
		.focus(function(){
			label.addClass('faded');
		})
		.blur(function(){
			var text = $(this).val();
			if (text.length == 0) {
				label.removeClass('faded hidden');
			}
		})
		.keyup(function(){
			var text = $(this).val();
			if (text.length > 0) {
				label
				.removeClass('faded')
				.addClass('hidden');
			}
			else{
				label
				.removeClass('hidden')
				.addClass('faded');
			}
		});
	});
});
