(function($) {
	$.fn.input_overlay = function(options) {
        
		// Plugin default settings 
		var defaults = {
			overlay: 'span',
			overlay_class: 'input-overlay',
			auto_position: 0
		};
        
		// Extending options
		var options = $.extend(defaults, options);
        
		return this.each(function() {
			var obj = $(this),
			value = obj.attr('value'),
			currentvalue = '';
			obj.removeAttr('value');
			
			//if (options.text_src == 'value')
			//{
			//	var value = obj.attr('value'),
			//	obj.removeAttr('value');
			//} 
			//else if (options.text_src == 'label')
			//{
			//	var value = obj.parent().closest('label').html();
			//	obj.parent().closest('label').hide();
			//}
			//else if (options.text_src == 'id')
			//{
			//	var value = obj.attr('id');
			//}
			
			var overlayHtml = '<'+options.overlay+' class="'+value+' '+options.overlay_class+'">'+ value +'</'+options.overlay+'>';
			obj.parent().css('position','relative').prepend(overlayHtml);
			
			if(options.auto_position == 1){
				var height = obj.outerHeight(), 
				fontsize = obj.parent().find('.'+options.overlay_class).outerHeight(true),
				remainder = (parseInt(height) - parseInt(fontsize)) / 2;
				remainder_left = remainder * 1.4;
				if(remainder <= 1){
					remainder_left = (height / 100 * 25);
				}
				
				obj
				.css({'line-height': height+'px', 'padding-left': remainder_left+'px'})
				.parent().find('.'+options.overlay_class)
				.css({'position':'absolute', 'top': remainder+'px', 'left': remainder_left+'px'});
			}
			
			
			obj.keyup(function () {
				var currentvalue = $(this).val();
			});

			obj.parent().find('.'+options.overlay_class).click(function(){
				$(this).hide();
				obj.focus();
				obj.focus(function(){
					obj.parent().find('.'+options.overlay_class).hide();
					if(obj.attr('type') == 'password'){
						$(this).val('');
					}
				}).keyup(function(){
					var currentvalue = $(this).val();
				}).blur(function(){;
					if (obj.val() == ''){
						obj.parent().find('.'+options.overlay_class).show();
					}
				})
			});
			obj.focus(function(){
				obj.parent().find('.'+options.overlay_class).hide();
				if(obj.attr('type') == 'password'){
					$(this).val('');
				}
			}).keyup(function(){
				var currentvalue = $(this).val();
			}).blur(function(){;
				if (obj.val() == ''){
					obj.parent().find('.'+options.overlay_class).show();
				}
			});
		});
	};
})(jQuery);
