$(function() {

  $('input', this).live('keydown', util.inlineLabel);
  $('input', this).live('paste', util.inlineLabel);

  $('input', this).live('focusin', function() { 
	$(this).prev('span').addClass("focus"); 
  });
  $('label.inline input, label.inline textarea').live('focusout', function() { 
	$(this).prev('span').removeClass("focus");
  });
  $('label.inline input, label.inline textarea').each(function() { 
	util.inlineLabel.call(this); 
  });

});

var util = {
  "inlineLabel": function() {
	var input = $(this);
	setTimeout(function() {
		var def = input.attr('title');
		if (!input.val() || (input.val() == def)) {
			input.removeClass("typing");
			input.prev('span').css('visibility', '');
			if (def) {
				var dummy = $('<label></label>').text(def).css('visibility','hidden').appendTo('body');
				input.prev('span').css('margin-left', dummy.width() + 3 + 'px');
				dummy.remove();
			}
		} else {
			input.addClass("typing");
			input.prev('span').css('visibility', 'hidden');
		}
	}, 250);
	// Copyright 2009 Stefano J. Attardi, http://attardi.org
  }
}
