jQuery(document).ready(function() {
	$ = jQuery;
	
	var added = 0;
	var removed = 0;
	$("#add-attachment").live('click', function(e){
		e.preventDefault();
		added++;
		$(this).before("<input id='form-attachment-" + added + "' type='file' name='attachments[" + added + "]'/>");
	});
	
	$("#files-attached .remove").live('click', function(e){
		var fileid = $(this).siblings("a.download").attr("id");
		e.preventDefault();
		removed++;
		
		$(this).parent().addClass("removed");
		$(this).text("Restore").attr("class", "restore");
		
		$("#files-attached").after("<input type='hidden' id='removed-" + fileid + "' name='attachments[remove][" + removed + "]' value='" + fileid + "' />");
	});
	
	$("#files-attached .restore").live('click', function(e){
		var fileid = $(this).siblings("a.download").attr("id");
		e.preventDefault();
		
		$(this).parent().removeClass();
		$(this).text("Remove").attr("class", "remove");
		
		$("#removed-" + fileid).remove();
	});
	
});

