/*
 * FaceValue (for jQuery)
 * Version 0.4 (02/25/09)
 * @requires jQuery v 1.3 or later
 * 
 *
 * Licensed under MIT:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright 2009 Robert R Evans - Code Wranglers, Inc.
 *
 * Usage
 * 
 *  jQuery(document).ready(function() {
 *   jQuery().facevalue();
 * })
 *
 *
 *
*/

(function($) {
  
  $.facevalue = function() {
    $.facevalue.setup();
    $.facevalue.swap();
  }
  
  $.extend($.facevalue, {

    // Populate the empty input values with the value from the title attribute
    setup: function() {
      $('.facevalue').each(function(i) { 
        
        if($.trim($(self).val()) === '') {
         $(this).val($(this).attr('title')); 
        }
                
      });
    },
    
    // Swap on focus and blur
    swap: function() {
      facevalues = []
      
      $('.facevalue').each(function(i) {
        
        // Well set the value from the title Attribute
        facevalues[i] = $(this).attr('title');
        
        $(this).focus(function() {
          if($(this).val() === facevalues[i]) {
            $(this).val('');
          }
        }).blur(function() {
          if($(this).val() === '') {
           $(this).val(facevalues[i]);
          }
        });
        
      });
      
    }
    
  });
  
  
  // Public Function
  $.fn.facevalue = function() {
    $.facevalue.setup();
    $.facevalue.swap();
  }

})(jQuery);
