function PostThreadedView(varName, treeName, contentContainerID, contextMenuName, viewPostUrl, initialPost) 
{
	this.VariableName = varName;
	this.TreeName = treeName;
	this.ContainerHandle = document.getElementById(contentContainerID);
	this.ContextMenuName = contextMenuName;
	this.ViewPostUrl = viewPostUrl;
	this.LastSelectedPost = initialPost;
	this.ContextMenuTreeNode = null;

	this.GetTree = function()
	{
		return eval(this.TreeName);
	}
	
	this.GetContextMenu = function()
	{
		return eval(this.ContextMenuName);
	}

	this.PostClick = function()
	{
		var tree = this.GetTree();
		if (tree.SelectedNode != null)
		{
			this.LastSelectedPost = tree.SelectedNode.Value;
			this.ContainerHandle.src = this.ViewPostUrl.replace(/\{0\}/g, this.LastSelectedPost);
		}
	}
	
	this.MovePost = function(sourceNode, targetNode)
	{
		if (!confirm('Are you sure you want to move the post \"' + sourceNode.Text + '\" to be in response to \"' + targetNode.Text + '\"?'))
			return false;
		else
		{
			PostThreadedViewAJAX.MovePost(this.VariableName, sourceNode.Value, targetNode.Value, new Function('result', 'window.' + this.VariableName + '.MovePostComplete(result);'));
			return true;
		}
	}
	
	this.MovePostComplete = function (result)
	{
		if (result.error)
			alert(result.error);
		else
			alert(result.value);
	}
	
	this.ShowContextMenu = function(treeNode, event)
	{
		this.ContextMenuTreeNode = treeNode;
		this.GetContextMenu().ShowContextMenu(event, treeNode);
	}
	
	this.ExpandChildNodes = function()
	{
		var tree = this.GetTree();
		var node = this.ContextMenuTreeNode;
		if (node != null)
		{
			if (!node.Expanded)
			{
				node.SetProperty('Expanded', true);
			}
			
			node.ExpandAll();
		}
	}
	
	this.CollapseChildNodes = function()
	{
		var tree = this.GetTree();
		var node = this.ContextMenuTreeNode;
		if (node != null)
		{
			node.CollapseAll();
			node.Collapse();
		}
	}
}
