(function($){
	$.inputfocusclass = function (){};
	$.fn.inputfocus = function (){
		$.inputfocus = $.inputfocus || new $.inputfocusclass();
		$(this).parents('form').submit(function(){
			$(this).find('[@rel*='+$.inputfocus.reltag+']').each(function(){
				$(this).focus();
			});
			return true;
		});
		this.each(function(){
			$(this).focus(function(){$.inputfocus.hidehover(this);});
			$(this).blur(function(){$.inputfocus.showhover(this);});
		});
	};
	$.extend($.inputfocusclass.prototype,{
		reltag:	'hovervalue',
		colortag: 'changecolor',
		typetag: 'changetype',
		defaultcolor: '#777777',
		domready: function(){
			var objli = $('[@rel*='+this.reltag+']');
			objli.each(function(){
				$.inputfocus = $.inputfocus || new $.inputfocusclass();
				if(typeof(this.value)!='undefined'&&this.value==''){
					$.inputfocus.showhover(this);
				}
			});
			objli.inputfocus();
			return true;
		},
		showhover: function(obj){
			var t = obj.title || '';
			if(typeof(obj.value)!='undefined'&&obj.value == ''){
				font_color = $(obj).css('color');
				if(font_color==''||font_color=='#000000'||font_color=='#FFFFFF'){
					$(obj).css('color',this.defaultcolor);
					$(obj).attr(this.colortag,font_color);
				}
				if(obj.type&&obj.type=='password'){
					$(obj).attr(this.typetag,obj.type);
					var h_input = $(obj).clone()[0];
					if(h_input.outerHTML){
						h_input = h_input.outerHTML;
						h_input = h_input.replace(/([\s'"]+)type(\s*=[\s'"]*)password([\s'"]+)/ig,'$1type$2text$3');
					}else{
						h_input.type = 'text';
					}
					var n_input = $(h_input).insertBefore($(obj));
					n_input.val(t);
					$(obj).remove();
					n_input.inputfocus();
				}else{
					obj.value = t;
				}
			}
		},
		hidehover: function(obj){
			var t = obj.title || '';
			if(typeof(obj.value)!='undefined'&&obj.value == t){
				if($(obj).attr(this.colortag)){
					$(obj).css('color',$(obj).attr(this.colortag));
					$(obj).removeAttr(this.colortag);
				}
				if($(obj).attr(this.typetag)&&$(obj).attr(this.typetag)=='password'){
					var h_input = $(obj).clone()[0];
					if(h_input.outerHTML){
						h_input = h_input.outerHTML ;
						h_input = h_input.replace(/([\s'"]+)type(\s*=[\s'"]*)text(['"]*)/ig,'$1');
						re = new RegExp(this.typetag,"ig");
						h_input = h_input.replace(re,'type');
					}else{
						h_input.type = 'password';
						$(h_input).removeAttr(this.typetag);
					}
					var n_input = $(h_input).insertBefore($(obj));
					n_input.val('');
					$(obj).remove();
					n_input.inputfocus();
					n_input.focus();
				}else{
					obj.value = '';
				}
			}
		}
	});
	$(function(){
		$.inputfocus = $.inputfocus || new $.inputfocusclass();
		$.inputfocus.domready();
	});
})(jQuery);
