/*
 * jQuery Simple Slideshow Plugin 1.0.0
 *
 * Copyright (c) 2009 Andria Klimov
 * Licensed under the MIT license (MIT-LICENSE.txt)
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Usage:
 * <label for="ID" class="CLASS" style="display: none;">Search...</label>
 * <input type="text" name="search" id="ID" />
 * <script> $('#ID').placeholder(); </script>
 */
(function($) {

  $.fn.placeholder = function() {

    // initialize plugin
    return this.each(function() {

      var $this = jQuery(this);

      // default values
      var value     = 'undefined';
      var className = 'undefined';
      
      // search label element
      var $set = jQuery('label');
      for (i = 0; i < $set.length; i++)
        if ($set.eq(i).attr('for') == $this.attr('id'))
          { value = $set.get(i).innerHTML; className = $set.get(i).className; break; }
      
      if ($this.val() == '' || $this.val() == value)
        $this.val(value).addClass(className);

      $this.focus(function() {
        if ($this.hasClass(className)) {
          jQuery(this).removeClass(className).val('');
        };
      }).blur(function() {
        if (this.value == '') {
          jQuery(this).addClass(className).val(value);
        };
      });

      if (this.form) {
        jQuery(this.form).submit(function() {
          if ($this.val() == value) {
            $this.removeClass(className).val('');
          }
        });
      }

    });
  };
})(jQuery);

