$(document).ready(function() {
    $.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();
        }
    }
    $("#form-wrapper label").each(function (i) {
        $(this).next("input").attr("value",$(this).html());
        $(this).hide();
    });
    $("#form-wrapper input").focus(function() {
        if($(this).prev("label").html() == this.value){
            $(this).addClass("focus").setCursorPosition(0);
			}
    });
    $("#form-wrapper input").keypress(function() {
        if($(this).prev("label").html() == this.value){
            this.value = "";
            $(this).removeClass("focus").addClass("typing");
        }
    });
    $("#form-wrapper input").blur(function() {
        $(this).removeClass("focus").removeClass("typing");
        if(this.value == ""){
        this.value = $(this).prev("label").html();
        }
    });
});
