$(document).ready(function() {
    $('[placeholder]').placeholder();
});

(function($) {
    var togglePlaceholder = function(obj, className) {
        className = typeof(className) != 'undefined' ? className : 'placeholder';
        var $obj = $(obj);

        if($obj.val() == '') {
            $obj.addClass(className)
                .val($obj.attr('placeholder'));
        }
        else if($obj.val() == $obj.attr('placeholder')) {
            $obj.removeClass(className)
                .val('');
        }
    }

    $.fn.placeholder = function() {
        var input = document.createElement('input')
        if(!('placeholder' in input)) {
            var $this = $(this);

            $this.each(function() {
                togglePlaceholder(this);
            });

            $this.live('focus blur', function() {
                togglePlaceholder(this);
            });

            $('form').live('submit', function() {
                $(this).find('.placeholder').val('');
            });
        }
        return this;
    }
})(jQuery);

