jQuery(function($){
		$('.styled').each(function(){
			// � ��������� ��� �� ������� ��� �������� �����
			/*$(this).removeClass('button');*/

			// ������� �������
			var BtnTable = document.createElement('table');
			var BtnTableRow = BtnTable.insertRow(0);
			var LeftBtnCell = BtnTableRow.insertCell(0);
			var CenterBtnCell = BtnTableRow.insertCell(1);
			var RightBtnCell = BtnTableRow.insertCell(2);

			// ��� �� ������ ������� ������ �������,
			// ������� ��� ��� �����-������ �������������� �������� DOM
			var newBtnContainer = document.createElement('em');
			var newBtnSideLContainer = document.createElement('i');
			var newBtnSideRContainer = document.createElement('i');

			// ��������� ������, ��������� � ����������
			$(LeftBtnCell).addClass('xBtn-Left').append(newBtnSideLContainer);
			$(RightBtnCell).addClass('xBtn-Right').append(newBtnSideRContainer);

			// ������������� �������,
			// ��������������� ��������� ��������� ���������� ������ �����
			newBtnContainer.setAttribute('uselectable', 'on');

			$(BtnTable)

				// ��������� ����� ��� ����� �������-������
				.addClass('xBtn')

				// ��������� �� �������� ������ �� �������� � ������� Title, ��� ������� ������������
				.attr('title', $(this).attr('value') || '')

				// ��������� ������� ��� ��������� � ����� �� �������-������
				.hover(
					function(){
						if ($('button:enabled', $(BtnTable)).length) $(this).addClass('xBtn-over');
					},
					function(){
						$(this).removeClass('xBtn-over');
						$(this).removeClass('xBtn-click');
					}
				)
				.mousedown(function(){
					//$(newBtn).focus();
					$(this).addClass('xBtn-click');
				})
				.mouseup(function(){
					$(this).removeClass('xBtn-click');
				});


			// ����� �������, ��� ������ �� ������� ����� ���������� ����� ��������
			// ������ �� ������� ����� �������� �� ����� ��� ������, ������ - �� ���� �����������.
			// ico ico-image

			// ����������, ���� �� � ��� ������, � ��� ��...
			var xBtnClasses = this.className.split(' ');
			var hasIco = $(this).hasClass('ico');
			var icoClassName = '';
			for (var i = 0; i < xBtnClasses.length; i++ ) {
				if (xBtnClasses[i].toString().match(/ico-\w+/)) icoClassName = xBtnClasses[i].toString();
			}

			// ������� �� ��������� ������ ���������� �� ������.
			if (hasIco && icoClassName) {
				$(this).removeClass('ico').removeClass(icoClassName)
			}

			// �������� � ����������� ������ � ������� ������� ������ �� ��������� (���������� ������)
			// ���������� �� ����������� ������� � ��������� � ��� ��������� ��� ������� ������
			$(CenterBtnCell).append(newBtnContainer).addClass(this.className).addClass('xBtn-Center');;

			// �������� ������� onclick ���������
			var onClickEv = $(this).attr('onclick');

			// ���� ���� ����� �������, �� ������������� ��� �� ��� �������-������
			if (jQuery.isFunction(onClickEv)) {
				$(BtnTable).bind('click', function(e){
					onClickEv();
				});

			// ���� ��� �������, �� ����� ���� ��� �������� ��� submit-��?
			// �������� �� ������ � ���� ������������
			} else if ( this.type == 'submit' ) {
				$(BtnTable).bind('click', function(e){
					if ($(this).find('button').length) {
						var f = $(this).find('button')[0];
						f.click();
					}
				});
			}

			// �������� ������ ����������� � ��������� ����� ��� �������� ����� ������
			$(this).hide().before(BtnTable);

			// ������ ���� ����������� ���� ������� ���� ������� ������� ������ �������� JavaScript.
			// �� � ����� � ������������ ��������� ��� IE, ������� ��������� �������� ������� type
			// ������ ������� ������� ��������:

			var Btn = '<button ' +
			   // ��������������� ��� ������
				'type="' +	($(this).attr('type') || 'button') +	'" ' +

				// ��������� ID ���������
				'id="' +	this.id +	'" ' +

				// �������� ������: ������, ���� ����,
				'class="' +	((hasIco && icoClassName) ? 'xBtn-text-ico ico ' + icoClassName : 'xBtn-text') + (($(this).attr('disabled')) ? ' disabled"' : '') + '" ' +

				// �������� ��������� ���������
				(($(this).attr('disabled')) ? 'disabled="disabled"' : '') +
				'name="' +	$(this).attr('name')   +	'" ' +
				'title="' +	$(this).attr('title')   +	'" ' +
				'style="' +	(($(this).attr('value') == '') ? 'width:16px;' : '')   +	'" ' +
				'>' + $(this).attr('value') +
				'</button>';

			// Tadaaaa!
			newBtnContainer.innerHTML = Btn;

			// ��������� ������������� � ������� ��� IE, ������ �� ������ ��������, ��� ����� ������, ����� ��� ����������� ������
			if ($.browser.msie && $(this).attr('value') != '') {
				if ($(CenterBtnCell).width()) {
					$(CenterBtnCell).find('button').css('width', $(CenterBtnCell).width() + 'px');
				} else {
					$(CenterBtnCell).find('button').css('width', TextMetrixWidth(this) + 18 + 'px');
				}
			}

			$(this).remove();
		});
	});

