/*
 * 	clearinput v1.0 - jQuery plugin
 *	written by Mike Wheeler
 *	http://www.korkoladesign.com
 *
 */

(function($) {

$.fn.clearinput = function(options) {

var defaults = {
defaultValue: '',
defaultClass: 'clearinput-default'
};

var options = $.extend(defaults, options);
var default_values = {};

this.each(function() {

var obj = $(this);
var id = $(obj).attr('id');

if (id) { // id required

default_values[id] = (options.defaultValue) ? options.defaultValue : $(obj).val(); 

//////////////////
// focusInput() //
//////////////////

function focusInput(obj) {
var id = $(obj).attr('id');
var value = $(obj).val();
$(obj).removeClass(options.defaultClass); // remove default class
if (value == default_values[id]) { // clear
$(obj).val('');
} // end clear
}

/////////////////
// blurInput() //
/////////////////

function blurInput(obj) {
var id = $(obj).attr('id');
var value = $(obj).val();
if (!value) { // set default
$(obj).val(default_values[id]);
} // end set default
value = $(obj).val();
if (value == default_values[id]) { // default class
$(obj).removeClass(options.defaultClass).addClass(options.defaultClass);
} // end default class
}

// focus

$(obj).focus(function() {	
focusInput(this);
});

// blur

$(obj).blur(function() {
blurInput(this);
});

blurInput(obj);

} // end id required

});

return this;

};

})(jQuery);

$(document).ready(function() {
$('.clearinput').clearinput();
});
