(function($){
	$.fn.jqFakeFile = function(settings){
		var imageMargin = 2;
		
		//Configurações por defeito
		settings = $.extend({
			buttonImage : 'none',
			imageWidth : 0,
			inputWidth : 0,
			fileHeight : 0
		}, settings);
		
		return this.each(function(){
			var that = $(this);
			var thatFile = $('input[type="file"]', that);
			
			//Adicionar position relative ao elemento pai
			that.css('position', 'relative');
			
			
			//Esconder a input file
			thatFile.css({
				'width' : that.width() + 'px',
				'height' : settings.fileHeight + 'px',
				'-ms-filter' : 'progid:DXImageTransform.Microsoft.Alpha(Opacity=0)',
				'filter' : 'alpha(opacity=0)',
				'opacity' : 0,
				'-moz-opacity' : 0,
				'position' : 'absolute',
				'top' : 0,
				'left' : 0,
				'padding' : 0,
				'z-index' : 2
			});
			
			
			var inputToAdd = document.createElement('input');
			inputToAdd.type = 'text';
			var divInput = $(document.createElement('div')).addClass("divInputfile").append(inputToAdd);
			
			//Adicionar elementos
			that.append($(divInput).css({
				'float' : 'left',
				'position' : 'relative',
				'z-index' : 1
			}), $(document.createElement('div')).addClass("btProcurar").css({
				'float' : 'left',
				'position' : 'relative',
				'width' : settings.imageWidth + 'px',
				'height' : settings.fileHeight + 'px',
				'background' : 'url(' + settings.buttonImage + ') no-repeat left top',
				'z-index' : 1
			}));
			
			var thatInput = $('input[type="text"]', that);
			
			//Eventos dos elementos adicionados
			thatInput.click(function(){
				thatFile.click();
				//Resolve o bug do event onchange no IE7
				thatInput.val(thatFile.val());
			});
			
			$('div', that).click(function(){
				thatFile.click();
				//Resolve o bug do event onchange no IE7
				thatInput.val(thatFile.val());
			});
			
			//Evento onchange da input file
			thatFile.change(function(){
				thatInput.val($(this).val());
			});
		});
	};
})(jQuery);
