(function($){
    $.fn.placeholder = function(options) {

        var def = {
            text : "aa",
            css_class : 'placeholder',
            callback_focus : null,
            callback_blur : null
        };
        var options = $.extend(def, options);

        return this.each(function() {
            setDefault(this);

            // On focus remove default text
            $(this).focus(function() {                
                var value = $.trim($(this).val());
                if(value == def.text) {
                    $(this).val("").removeClass(def.css_class);
                    if(def.callback_focus != null) {
                        def.callback_focus();
                    }
                }
              
            });

            // On blur revert to default text, if nothing is changed...
            $(this).blur(function() {
                var value = $.trim($(this).val());
                if(value == "" || value == def.text) {
                    setDefault(this);
                    if(def.callback_blur != null) {
                        def.callback_blur();
                    }

                    return;
                }
            });
        });
        function setDefault(e) {
            $(e).val(def.text).addClass(def.css_class);
        }
    };
})(jQuery);



