function Content( sContentElement )
{
	if ( !document.getElementById || !this.initContent( sContentElement ) )
		alert( 'Content could not be initialized' );
};

Content.prototype.initContent = function( sContentElement )
{
	this._rpc = '/rpc.php';
	this._sLastClicked = '';
	this._currentpage = 1;
	this._pages = 1;
	this._nLimit = 2;
	this._selectedCategory = false;
	this._eContent = document.getElementById( sContentElement );
	
	return true;
};

Content.prototype.loadContentByCode = function( sCode )
{
	this._sCode = sCode;
	if ( typeof iPage == "undefined" )
		iPage = 1;
				
	this.displayContent( sCode );
	return false;
};

Content.prototype.displayContent = function( sCode )
{
	var oXML     = new klib3.xml();
	oXML._parent = this;
	
	oVariable = new Object();
	oVariable.command = "loadcontentbycode";
	oVariable.code = sCode;
	oVariable._format = 'xml';
	
	if ( typeof this.onload == "function" )
		oXML.onload = this.onload;
	else
	{
		oXML.onload  = function()
		{
			this._parent._onActivateContent( this.getData().firstChild );
		}
	}
	
	if ( oXML.post( this._rpc, true, oVariable ) )
		return true;
	else
		return false;
};

Content.prototype.getSiblingByName = function ( oNode, sName )
{
	if ( oNode )
	{
		while ( ( oNode.nodeType != 1 || ( oNode.nodeName && oNode.nodeName.toLowerCase() != sName.toLowerCase() ) ) && oNode.nextSibling )
			oNode = oNode.nextSibling;
			
		if ( oNode.nodeType == 1 && ( oNode.nodeName && oNode.nodeName.toLowerCase() == sName.toLowerCase() ) )
			return oNode;
	}
	
	return false;
};

Content.prototype.getNodeValue = function( oNode )
{
	if ( oNode )
	{
		if ( oNode.nodeType == 3 || oNode.nodeType == 4 )
			return oNode.nodeValue;
			
		return arguments.callee( oNode.firstChild );
	}
	return false;
};

Content.prototype.__doActivateContent = function()
{
	this._parent.activateContent( this._cat, this._index );
	return false;
};

Content.prototype.addContent = function( sId, sTitle, sContent )
{			
	var eTitle = document.createElement( 'div' );
	eTitle.innerHTML = sTitle;
	eTitle.className = "title";
	
	var eContent = document.createElement( 'div' );
	eContent.innerHTML = sContent;
	eContent.className = "content";
			
	var eItem = document.createElement( 'div' );
	eItem.appendChild( eTitle );
	eItem.appendChild( eContent );
	
	this._eContent.appendChild( eItem );
	
	return true;
};

Content.prototype.clearContent = function ()
{
	this._eContent.innerHTML = "";
};

Content.prototype._onActivateContent = function( oXML )
{
	if ( oXML && oXML.childNodes && oXML.childNodes.length > 0 )
	{
		for ( var i = 0; i < oXML.childNodes.length; ++i )
		{
			var oItem = oXML.childNodes[ i ];
			
			if ( oItem.nodeType == 1 && oItem.nodeName == "content" )
			{
				this.clearContent();
				
				var sId = this.getNodeValue( this.getSiblingByName( oItem.firstChild, "id" ) );
				var sContent = this.getNodeValue( this.getSiblingByName( oItem.firstChild, "content" ) );
				var oProperty = this.getSiblingByName( oItem.firstChild, "_property" );
				var sTitle = this.getNodeValue( this.getSiblingByName( oProperty.firstChild, "title" ) );
				
				this.addContent( sId, sTitle, sContent );
			}
		}
	}
};
