Content = function(ph)
{
    this.placeHolder = ph;

    this.loader = new Loader();
    this.loader.setHandler(4, this.handler(this.loadedHandler));
    
    this.name = "";
    this.nodes = null;
    this.selectedIndex = 0;
}

Content.prototype.load = function(contentName)
{
	if (this.name == contentName)
	{
		return;
		
	}
	// reset
	this.name = contentName;
	this.selectedIndex = 0;
	this.placeHolder.innerHTML = "";
	
	if (contentName!= "")
	{
		this.loader.load(config.contentFolder + "Page/" + contentName + ".xml", true);
	}
}

Content.prototype.next = function()
{
	if ((this.nodes != null) && (this.nodes.length > this.selectedIndex))
	{
		this.selectedIndex++;
		
		this.showSelected();
	}
}

Content.prototype.prev = function()
{
	if ((this.nodes != null) && (this.selectedIndex > 0))
	{
		this.selectedIndex--;
		
		this.showSelected();
	}
}

Content.prototype.loadedHandler = function()
{
	var xmlDoc = this.loader.getXML();
    if(xmlDoc == null)
    {
        return;
    }
    
    // TODO: implement ContentModel (see menu);
    
    this.nodes = xmlDoc.getElementsByTagName("view");
    
    this.showSelected();
}

Content.prototype.showSelected = function()
{
	this.placeHolder.innerHTML = "";
	
	if (this.nodes.length > 0)
    {
		var selectedNode = this.nodes[this.selectedIndex];
		for(var i = 0; i < selectedNode.childNodes.length; i++)
		{
			this.placeHolder.appendChild(convert.toElement(selectedNode.childNodes[i]));
		}
    }
}

Content.prototype.handler = function(handler)
{
    var ref = this;
    return function()
    {
        handler.apply(ref, arguments)
    }
}

