jQuery.fn.uploadButton = function(o) {

	var imageSrc='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAABACAMAAABMUIWcAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADBQTFRF7e/s+60H/ehi/soG//WaKB8G/dkz/OsCwcLBkG0T2bNL+KEA/7gA/7QAAAAAAAAAojnAqAAAABB0Uk5T////////////////////AOAjXRkAAAGoSURBVHjaxJRZgoQgDETDqiym73/bSYJoaBVnvqaI7ZLqCAgPPi+CfzCg1o0BQ1INLwZMi1YJF4MbDEtCkLKnlsUt7ojFBfiEkO3R6PEoNng4ZTdXdb4GwAz+aOCN2TZztLqRwXqtWkZdDN5qmYKA0duzWbKrsFwh2oliM0i0s40qbBTDo9pEoXvK7hN1Nbg4zCRWNxMb4iTPU23U7RmtiYEuutx3tAp1IvNm4K9Z6vYoqTAzbGxIZiL63J/g+OI+Nl7VGMqjEvK+QL3sByH+ffN+VbgYcAWt8GZIo4GBsMJKcV8hpJWSZFjlLBWGUSR6shvaFe3UgroCJ3uFZoudD6ywG6D1QSpk4QNNtSm55VQJNsTGB1qMuXVK8tB/qIIsuWJSSfl48dAHwysqldrJJaXUOLPh3V0cUQF2OsRzGGwQgBjNKJ/1K1IjzP5vkIN6TJuT30dDMCW9IMgJYXpmPwZ3xTmCfJwzKgqCnH1CEPP6EUEKIEaoo+OLMOdNvGBkJEwjRieHAogjQtxBQsjzO8K8AmQGCJwDpAof0i/4QIv+LpgPPwIMAJo8PGIkyYGIAAAAAElFTkSuQmCC';	
	
	var s = {
		'width': '200px',
		'height': '22px',
		'paddingHeight': '4px',
		'paddingLeft': '4px',
		'background': 'white',  
		'borderRadius': '5px',
		'borderColor': '#ddd',
		'borderColorOver': 'blue',
		'borderWidth': '2px',
		'borderStyle': 'solid',
		'buttonImage': imageSrc,
		'buttonWidth': '32px',
		'buttonHeight': '32px',
		'buttonChange': true,
		'buttonMargin': '4px'
		};

	return this.each(function() {        

		if (o) { $.extend( s, o ); }      
      
		var $this = $(this);

		$($this).css({
			'opacity': 0, 
			'position': 'absolute', 
			'font-size': '400px', 
			'top': 0, 
			'right': 0, 
			'z-index': 1,
			'cursor': 'pointer',
			'float': 'left'	
			});

		$($this).wrap('<div class="fub-file" />');
		$('.fub-file').css({
			'display': 'block',
			'overflow': 'hidden', 
			'position': 'relative',
			'float': 'left'	
		});

		$('<span class="fub-show" />').insertBefore($this);		
		$('.fub-show').css({
			'cursor': 'pointer',
			'display': 'block',
			'width': s.width,			
			'min-height': s.height, 
			'padding-top': s.paddingHeight,
			'padding-bottom': s.paddingHeight,			
			'padding-left': s.paddingLeft,			
			'margin-right': s.buttonMargin,
			'background': s.background,  
			'overflow': 'hidden', 
			'position': 'relative',
			'border-width': s.borderWidth,
			'border-style': s.borderStyle,
			'border-color': s.borderColor,
			'-moz-border-radius': s.borderRadius,
			'-webkit-border-radius': s.borderRadius,
			'border-radius': s.borderRadius,
			'white-space': 'nowrap',
			'float': 'left'		
		});
		
		$('.fub-file').mouseover(function(){
			$('.fub-show').css({
				'border-color': s.borderColorOver
			});
		}).mouseout(function(){
			$('.fub-show').css({
				'border-color': s.borderColor
			});
		});

		$('<span class="fub-button" />').insertAfter($this);
		$('.fub-button').css({
			'background': 'url('+s.buttonImage+') no-repeat 0 0',  
			'width': s.buttonWidth, 
			'height': s.buttonHeight, 
			'cursor': 'pointer', 
			'text-indent': '-9999px', 
			'display': 'block', 
			'float': 'left',
			'z-index': 1,
			'position': 'relative'
			});

		$($this).bind('change', function() {
			$(this).prev().text($this.val());
			
			if(s.buttonChange == true){			
				$('.fub-button').css({
					'background-position': '0px -'+s.buttonHeight
				});
			}
			
			$(this).attr('title', $this.val());
		});
	});
};
