/*
 * Focus Input Type Text v1.0 
 * Copyright (c) 2009 FG Forrest, a. s.
 * 
 * Date: 2009-10-19 10:55 
 */
(function($) {  
	/* plugin definition */
	$.fn.fitt = function(options) {
		// build main options before element iteration  
		var opts = $.extend({}, $.fn.fitt.defaults, options);
		// iterate each matched element
		return this.each(function() {
			$this = $(this);
			// build element specific options
			var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
			// focus obj
			$this.focus(function(){
				$.fn.fitt.focusObj(this,o.classBlur,o.classFocus);
			});
			// blur obj
			$this.blur(function(){
				$.fn.fitt.blurObj(this,o.classBlur,o.classFocus);
			});
		}); // end RETURN  
	};

	/* Define engine function  */
	$.fn.fitt.focusObj = function(obj,classBlur,classFocus) {
		$(obj).removeClass(classBlur).addClass(classFocus);
		if (obj.value == obj.defaultValue){
			obj.value = '';
		}
		if(obj.value != obj.defaultValue){
			obj.select();
		}
	};

	$.fn.fitt.blurObj = function(obj,classBlur,classFocus) {
		$(obj).removeClass(classFocus).addClass(classBlur);
		if ($.trim(obj.value) == ''){
			obj.value = (obj.defaultValue ? obj.defaultValue : '');
		}
	};

	/* Defaults setting */
	$.fn.fitt.defaults = {
		classBlur: 'text',
		classFocus: 'text'
	};
})(jQuery);
