(function($) {

	$.fn.filestyle = function(options) {

		var settings = {
			buttonImage:	'',
			buttonHeight:	'',
			buttonWidth:	''
		};

		if (options) {
		    $.extend(settings, options);
		};

	    return this.each(function() {
		    var self = this;

			$(self).wrap('<div class="fileWrap"></div>');

			$('.fileWrap').css({
				//'border': '1px solid red'
			});

			var wrapper = $('<div class="fileButton">').css({
				'position': 'relative',
				'width': settings.buttonWidth + 'px',
				'height': settings.buttonHeight + 'px',
				'overflow': 'hidden',
				//'border': '1px solid blue',
				'background': 'url(/media_front/images/input/' + settings.buttonImage + ') no-repeat 0% 100%'
			});

			$(self).wrap(wrapper);

			$(self).css({
				'position': 'absolute',
				'right': '0px',
				'cursor': 'text',
				'width': 'auto',
				'height': settings.buttonHeight + 'px',
				//'background-color': 'transparent',
				'opacity': '0.0'
			});


			$(self).bind('change', function() {
				var fileVal = $(self).val();

				//$('.formAlert').html(fileVal);

				if ( fileVal != '' ) {
					$(this).parent('.fileButton').css('background-position', '0% 0%');
				}
	        });
		});

	};

})(jQuery);
