(function (jQuery) {
    jQuery.fn.extend({
        showPassword: function (checkbox, password, callback) {
            return this.each(function () {

                var createClone = function (el) {
                    var $el = $(el),
						$clone = $("<input type='text' />");

                    var el = $clone.insertAfter(el).attr({
                        'class': $el.attr('class'),
                        'style': $el.attr('style')
                    });
                    return $clone;
                };




                var update = function ($this, $that) {
                    $that.val($this.val());
                };
                var set = function () {
                    if ($checkbox.is(':checked')) {
                        update($this, $clone);
                        $clone.show();
                        $this.hide();
                    } else {
                        update($clone, $this);
                        $clone.hide();
                        $this.show();
                    }
                };
                var $clone = createClone(this),
					$this = $(this),
					$checkbox = $(checkbox);
                $checkbox.click(function () { set(); });
                $this.keyup(function () { update($this, $clone); });
                $clone.keyup(function () { update($clone, $this); });

                set();
                if (password) {
                    $clone.val(password);
                    $this.val(password);
                }                
                if (callback) {
                    callback()
                }
            });
        }
    });
})(jQuery);
