$.fn.onbutton = function() {
	var tr = $(this).find("TR");
	var count = tr.length;
	if(count>1){
		for(var i=0; i<count; i++){
			$(tr[i]).find("INPUT[name=drop]").attr({"disabled":false});
		}
		$(tr[i-1]).find("INPUT[name=drop]").attr({"disabled":true});
		$("INPUT#submit").attr({"disabled":false});
	}else{
		$("INPUT[name=drop]").attr({"disabled":true});
		$("INPUT#submit").attr({"disabled":true});
	}
};
$.fn.deleterow = function() {
	$(this).click(function(){
		var parent = $(this).parent().parent();
		if($(parent).find("INPUT:first-child").attr("value")=="") return false;
		$(parent).remove();
		$("#file").onbutton();
	});
};
$.fn.copyrow = function() {
	$(this).change(function(){
		$("#file").find("TR:first-child").clone(true).appendTo("#file"); 
		var last = $("#file").find("TR:last-child");
		$(last).find("INPUT[type=file]").attr("value",""); 
		$("#file").onbutton();
	});
};
$(document).ready(function(){
	$(".files INPUT").copyrow();
	$("#file").onbutton();
	$("INPUT[name=drop]").deleterow();
	$(".files INPUT").length;
});
