jQuery.fn.file = function(options){
	var settings = {
		className: 'jquery-file',
		classInvisible: 'jquery-file-invisible',
		classField: 'jquery-file-field',
		classButton: 'jquery-file-button',
		replaceInvisible: true
	};
	var commonClass = 'jquery-file-replaced';
	settings = jQuery.extend(settings, options || {});
	return this.each(function() {
		var _this = jQuery(this);
		if(_this.filter(':visible').length == 0 && !settings.replaceInvisible)
			return;
		var replacement = jQuery(
			'<div class="'+settings.className+'"><span class="field"><input type="text" class="text '+settings.classField+'" value="'+this.value+'" /></span><input type="button" value="Browse" class="button  '+settings.classButton+'" /><span class="holder"></span></div>'
		);
		_this.replaceWith(replacement).appendTo(replacement);
		_this.appendTo(replacement.find('span.holder')[0]);
		_file = replacement.find('input.file')[0];
		_this = jQuery(_file);
		_file._input = replacement.find('span.field input.text')[0];
		_file._button = replacement.find('input.button')[0];
		_file.onchange =  function() {
			_file._input.value = this.value;
		}
		_this.bind("mouseover", function(){$(this._button).addClass("button-hover");}).bind("mouseleave", function(){$(this._button).removeClass("button-hover");});
		
		_this.css({"opacity": 0, "visibility": "visible"});
		_this.addClass(settings.classInvisible);
	});
}
