jQuery(function($) {
  $('input[type=text][title],input[type=password][title],textarea[title]').each(function(i){
    var $this = $(this);
    $this.addClass('input-prompt-' + i);
    $this.wrap('<div style="position:relative"/>');
    function fixedCss(t, p) { return parseInt(0 + t.css(p).replace(/[^0-9]/g, '')); }
    var promptSpan = $('<div class="input-prompt"></div>').css({
      'position': 'absolute',
      'top': fixedCss($this, 'border-top-width') + fixedCss($this, 'padding-top')
        + fixedCss($this, 'margin-top') + 'px',
      'left': fixedCss($this, 'border-left-width') + fixedCss($this, 'padding-left')
        + fixedCss($this, 'margin-left') + 'px',
      'line-height': $this.css('line-height'),
      'font-family': $this.css('font-family')
    });
    $(promptSpan).attr('id', 'input-prompt-' + i);
    $(promptSpan).append($this.attr('title'));
    $(promptSpan).click(function(){
      $(this).hide();
      $('.' + $(this).attr('id')).focus();
    });
    if($this.val() != ''){
      $(promptSpan).hide();
    }
    $this.before(promptSpan);
    $this.focus(function(){
      $('#input-prompt-' + i).hide();
    });
    $this.blur(function(){
      if($(this).val() == ''){
        $('#input-prompt-' + i).show();
      }
    });
  });
});


