/* Copyright (C) 2009 Pierre Allain (contact@p3x.fr) - http://expeo.net/
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2009-02-06 04:38:37 +0100  $
 * $Rev: 115 $
 *
 * Version: 1.0b
 */
 
(function($) {
  $.fn.ghostText = function(options) {
  
    var defaults = {
      ghostColor:       '#999',
      ghostFontStyle:   'italic',
      color:            '#000',
      fontStyle:        'normal'
    };
    
    var opts = $.extend(defaults, options);
    
    var color = $(this).css('color');
    var fontstyle = $(this).css('font-style');
    var $this = $(this);
    $(this)
    
      .css('font-style', opts.ghostFontStyle)
      .css('color', opts.ghostColor)
      
      .focus(function() {
        if ($this.val() == $this[0].defaultValue) {
          $this.val('');
          $this.css('font-style', opts.fontStyle);
          $this.css('color', opts.color);
        }
      })
      
      .blur(function() {
        if ($(this).val() == '') {
          $(this).css('font-style', opts.ghostFontStyle);
          $(this).css('color', opts.ghostColor);
          $(this).val($(this)[0].defaultValue); 
        }
      });
  };
})(jQuery);