(function ($) {

    $.input = function (el, options) {
        var self = this,
			node = $(el),
			input = node[0];

		node.data('input', self);

		/**
		 *	Initializing
		 */
        this.init = function () {
            this.options = $.extend({}, $.input.defaultOptions, options);

			if (input.value != '' && input.value != input.title) {
				node.addClass('focused');
			} else {
				node.val(input.title);
			}

			node.focus(this._onFocus)
				.blur(this._onBlur);

			if (node.next().is('[type="password"]')) this.type = 1;
			if (node.is('[type="password"]')) this.type = 2;
        };


		this._onFocus = function () {
			if (self.type == 1) $(this).hide().next().addClass('focused').show().focus();
			else if (this.title == this.value) {
				$(this).addClass('focused');
				this.value = '';
			} else {
				this.select();
			}
		};

		this._onBlur = function () {
			if (this.value == '') {
				if (self.type == 2) $(this).hide().prev().show();
				$(this).removeClass('focused');
				this.value = this.title;
			}
		};

        this.init();
    };

    $.input.defaultOptions = {
    };

    $.fn.input = function (options) {
        return this.each(function () {
            (new $.input(this, options));
        });
    };

})(jQuery);

$('.input').input();
