var swf_file_load = new SWFObject("cubator/img/file_upload.swf", "mymovie", "100%", "20", "8");
swf_file_load.addParam("wmode", "transparent");

var input_file_arr=new Array();

jQuery.fn.input_file=function ()
{
	var id=$(this).attr('id');
	var _action=$(this).attr('_action');
	var _root=$(this).parent();
	var _this=$(this);
	$(_root).find("span.forma_del_file").click(function()
		{
			if (confirm("Удалить?"))
			{
				$(_this).attr("value", "");
				$(_root).find("div[tip=sost_div]").hide('fast', function() { $(this).html(''); });
				$(_root).find("input.input_file_text").attr("value", "");
			}
		}
		);
	input_file_arr[id]=new AjaxUpload($(_root).find(".input_file_but"), {
						  action: _action,
						  name: 'box_upload',
						  autoSubmit: false,
						  responseType: false,
						  onChange: function(file, extension){
						  	$(this).attr("value", "");
							$(_root).find("div[tip=sost_div]").hide('fast', function() { $(this).html(''); });
							//$(_root).find("div[tip=sost_div]").html('');
							$(_root).find("input.input_file_text").attr("value", file);
							$(_root).find("div.input_foto_wh").show('fast');
						  },
						  onSubmit: function(file, extension) {
						  	swf_file_load.write($(_root).find("td.input_file_text_td").attr('id'));
						  },
						  onComplete: function(file, response) {
							$(_root).find("td.input_file_text_td").html("<input type=\"text\" class=\"input_file_text\" id=\""+$(this).attr('id')+"_text\" readonly/>");
							if ((response=='error')||(response==''))
							{
								$(_root).find("div[tip=sost_div]").html('Ошибка');
								$(_root).find("div[tip=sost_div]").attr("class", "input_file_sost_text_no");
							}
						  	else
							{
								$(_this).attr("value", response);
								if (_cubator)
								{
									dop_put="cubator/";
								}
								else
								{
									dop_put="";
								}
								$(_root).find("div[tip=sost_div]").html("<div class=\"input_file_sost_div_complete_file\">"+response+"&nbsp;</div> <span class=\"forma_del_file\"><div class=\"but_div\" _button=\"del\"><div class=\"but_div_over\"><a href=\"#\" onClick=\"return false;\"><img src=\""+dop_put+"img/but_del1.gif\" border=\"0\" width=\"16\" height=\"16\"></a></div><img src=\""+dop_put+"img/but_del.gif\" border=\"0\" width=\"16\" height=\"16\"></div></span>");
								//$(_root).find("div[tip=sost_div]").html("<div class=\"input_file_sost_div_complete_file\">"+response+"&nbsp;</div>");
								$(_root).find("div.but_div_over").hide();
								$(_root).find("div.but_div").hover(
									function()
									{
										$(this).find(".but_div_over").show();
									},
									function()
									{
										$(this).find(".but_div_over").fadeOut(300);
									});
								$(_root).find("span.forma_del_file").click( function()
									{
										if (confirm("Удалить?"))
										{
											$(_this).attr("value", "");
											$(_root).find("div[tip=sost_div]").hide('fast', function() { $(this).html(''); });
											$(_root).find("input.input_file_text").attr("value", "");
										}
									}
								);
								$(_root).find("div[tip=sost_div]").attr("class", "input_file_sost_text_ok");
								$(_root).find("div[tip=sost_div]").slideDown(300, function () { $(this).parents("form").submit(); } );
								
								//setTimeout('$(this).parents("form").submit()', 300);
							}
						  }
				});
	
	return this;
};

