/**
 * cyOverlabel v.0.1.1
 * Overlabels lay truly semantic labels onto an input field to shorten the form. 
 * This plugin is a little helper to achieve this without recoding it every 
 * time. Labels to be dealed with have to have the class overlabel. After being
 * dealed with they've got the class overlabel-apply. Maybe the classnames will
 * become options later on
 * 
 * Usage: $('body').cyOverlabel();
 */

(function($) { 
  $.fn.extend({
    cyOverlabel: function(options) {
      
      /* fuer jedes label mit klasse overlabel */
      $('label.overlabel').each(function() {
        
        /* label merken */
        var label = this;
        
        /* overlabel entfernen und overlabel-apply einsetzen */
        $(label).removeClass('overlabel');
        $(label).addClass('overlabel-apply');
        
        /* wenn ein standartwert vorhanden ist, das label herausverschieben */
        if($('input[id=\''+$(label).attr('for')+'\']').attr('value') != '') {
          $(label). css('text-indent', '-9999px');
        }
        
        /* beim focus das label herausverschieben */
        $('input[id=\''+$(label).attr('for')+'\']').focus(function() {
          $(label).css('text-indent', '-9999px');
        });
        
        /* beim blur das label wieder reinschieben, wenn kein wert da ist */
        $('input[id=\''+$(label).attr('for')+'\']').blur(function() {
          if($(this).attr('value') == '') {
            $(label).css('text-indent', '0');
          }
        });
      });
    } 
  }); 
})(jQuery);
