﻿/*
jQuery Clear-Input Plugin v1.0
Author: Aidan Feldman
Modify: Yasin KUYU
*/
(function( $ ){
  // define the initialValue() function
  $.fn.initialValue = function(value) {
    if (value) {
      return this.attr('temp-value', value);
    } else {
      return this.attr('temp-value');
    }
  };
  
  $.fn.clearInput = function() {
    return this
      .focus(function(){
			// modify: get item attr value
			var title = $(this).attr("title")
			if (title !== '') {
				this.value = title;
			}
			else
			{
			if (this.value == $(this).initialValue()) {
				this.value = '';
			}
			}
      })
      .blur(function(){
		// modify: get title
        if (this.value == '' || $(this).attr("title") == $(this).value) {
			this.value = $(this).initialValue();
		}
      })
      .each(function(index, elt) {
        $(this).initialValue(this.value);
      });
  };

  // apply plugin to all inputs with class ".clear-input" input[type=text]
  $(function() {
    $('input[type=text],input[type=password]').clearInput(); 
  });
})( jQuery );
