(function ($) {
	$(document).ready(function(){


		//input: label to value
		$.fn.setCursorPosition = function(pos) {
			if ($(this).get(0).setSelectionRange) {
				$(this).get(0).setSelectionRange(pos, pos);
			} else if ($(this).get(0).createTextRange) {
				var range = $(this).get(0).createTextRange();
				range.collapse(true);
				range.moveEnd('character', pos);
				range.moveStart('character', pos);
				range.select();
	        }
	    }

		$('label').each(function (i) {
			$(this).next('input[type=text], input[type=password], input[type=file], textarea').val($(this).html());
			$(this).hide();
		});

		$('input[type=text], input[type=password], input[type=file], textarea').focus(function() {
			if($(this).prev('label').html() == $(this).val()){
				$(this).val('').setCursorPosition(0);
			}
		});

		$('input[type=text], input[type=password], input[type=file], textarea').keypress(function() {
			if($(this).prev('label').html() == $(this).val()) {
				$(this).val('');
			}
		});

		$('input[type=text], input[type=password], input[type=file], textarea').blur(function() {
			if($(this).val() == '') {
				$(this).val($(this).prev('label').html());
			}
		});

		//legal note
		$('#legal a.button').click(function(e) {
			e.preventDefault();
			$('#legal p').slideToggle(350);
			$(this).toggleClass('open');
		});


	});
}) (jQuery);
