/**
 * jquery.compact_input.js
 *
 * Takes a form label value puts it inside its associated input.
 * Requires a valid "for" attribute on the label.
 */
(function($){ 
	$.fn.compact = function() { 
    this.each(function() {
      var $input = $(this);
      var $label = $(this).siblings('label');
      if ($label.length < 1) { return this; }
      var decoy = '';
      var $decoy = null;
      if (this.nodeName == "TEXTAREA") {
        decoy = '<textarea class="' + this.className + ' ' + $label.get(0).className + ' decoy">'+$label.text()+'</textarea>';
        $input.after(decoy);
        $decoy = $input.siblings('textarea.decoy');
      }
      else {
        decoy = '<input type="text" class="' + this.className + ' ' + $label.get(0).className + ' decoy" value="' + $label.text() + '" />';
        $input.after(decoy);
        $decoy = $input.siblings('input.decoy');
      }
			$input.blur(function() {
        if ($input.val() == '') {
          $decoy.show();
          $input.hide();
        }
      }).hide();
      $decoy.focus(function() {
        $decoy.hide();
        $input.show().focus();
			});
      $label.hide();
    });
		return this;
	}; 
})(jQuery);

