	function showAttachments(action) {
		var divId = 'postattachments';
		
		var uploadDiv = $$("#" + divId + " *.uploadattachments")[0];
		var browseDiv = $$("#" + divId + " *.browseattachments")[0];
		
		$('attachmentsHide').style.display = 'block';
		
		if (action == "upload") {
			browseDiv.style.display = 'none';
			uploadDiv.style.display = 'block';
		} else {
			uploadDiv.style.display = 'none';
			browseDiv.style.display = 'block';
			browseDiv.innerHTML = '';
			
			var loadImage = document.createElement('img');
			loadImage.src = 'theme/images/loading.gif';
			loadImage.style.margin = '5px auto';
			loadImage.style.display = 'block';
			loadImage.id = 'fileBrowseLoader';
			browseDiv.appendChild(loadImage);
						
			var ajax = new Request({url: "functions/fileuploader/files.php?folder=" + postFolder + "&id=" + postId, method: "get",
				onSuccess: function(html) {
					showAttachmentFiles(html, 'insert');
				},
				onFailure: function() {
					showAttachmentFiles('error', 'insert');
				}
			});
			
			ajax.send();
		}	
	}
	
	function hideAttachments() {
		var divId = 'postattachments';
		
		var uploadDiv = $$("#" + divId + " *.uploadattachments")[0];
		var browseDiv = $$("#" + divId + " *.browseattachments")[0];
		
		browseDiv.style.display = 'none';
		uploadDiv.style.display = 'none';		
		$('attachmentsHide').style.display = 'none';
	}
	
	function showAttachmentFiles(responseText, way) {
		var divId = 'postattachments';
		var browseDiv = $$("#" + divId + " *.browseattachments")[0];
		
		var loadImage = browseDiv.getElementsByTagName("img")[0];
		browseDiv.removeChild(loadImage);
		
		if (way == "insert")
			browseDiv.innerHTML = responseText;
		else if (way == "adopt")
			browseDiv.adopt(responseText);
	}
	
	function deleteAttachment(directory, filename, parameters) {
		if (confirm(lang_pages_post_attachment_delete)) {
			var lis = $('postattachments').getElementsByTagName("ul")[1].getElementsByTagName("li");
			for (var i = 0; i < lis.length; i++) {
				var thisfilename = lis[i].getElementsByTagName("span")[2].innerHTML;
				if (thisfilename == filename) {
					removeAttachment(lis[i]);
				}
			}
			
			//alert("functions/fileuploader/deletefile.php?file=" + directory + filename + '&' + parameters);
			var ajax = new Request({url: "functions/fileuploader/deletefile.php?file=" + directory + filename + '&' + parameters, method: "get"});
			ajax.send();
		}
	}
	
	function removeAttachment(li) {
		var parent = li.parentNode;
		var fx = new Fx.Morph(li, {'duration': 1000});
		fx.start({
			'opacity': 0
		}).chain(function() {
			parent.removeChild(li);
		});
	}