var onehtml;
$(document).ready(function() {
	var f_els = $('input[type="file"]', '.fwrap');
	f_els.removeAttr('disabled');
	if (! $.browser.msie) {
		f_els.live('change', function(){//добавление файла (ред. нет)
			addFile($(this));
		});
	} else {
		f_els.live('click', function(event){
			var target = $(this);
			setTimeout(function(){addFile(target);}, 0);
		});
	}
	$('.fileinputs a[class*="delfile"]').live('click', function(){
		$(this).closest('.onefile').remove();
	});
	onehtml = $('.fileinputs').html();
});

function addFile(target) {
	if (!onehtml) {
		onehtml = $('.fileinputs').html();
	}
	var val = $(target).val();
	val = val.replace(/^.*(\\|\/)/gi, "");
	if (val.length == 0) {
		return;
	}
	$(target).css('z-index', '0');
	$(target).css('visibility', 'hidden');
	var mywrap = $(target).closest('.fwrap');
	mywrap.find('button.under').remove();
	mywrap.find('input.blanctext').remove();
	mywrap.find('.errors').remove();
	var ta = mywrap.find('textarea').last();
	$(ta).css('z-index', '2');
	var rows = Math.max(1, Math.ceil(val.length*11/ta.width()) - 0);
	ta.attr('rows',rows);
	ta.css('height', 'auto');
	ta.height(ta.height()+8);
	$(target).height(ta.height());
	$(target).width(ta.width()-2);
	ta.val(val);
	ta.removeClass('nodisplay');
	ta.addClass('over');
	mywrap.css('float','left');
	mywrap.closest('.onefile').append('<a href="javascript:void(0);" class="sublink delfile">удалить</a><div class="clear"></div>');
		
	mywrap.closest('.fileinputs').append(onehtml);
	initButtonStyle(mywrap.closest('.fileinputs'));
}


