/**
 * \class Dynamic Content Management
 * This class controls dynamic pre renderered content
 *
 * \param prefix Prefix of div list id
 * \event onChange Fired when content is updated
 */
DynamicContent = function(prefix)
{
  this.__construct = function(prefix) 
  {	  
	  this.mPrefix = prefix;
	  this.mContent = null;
	  this.mCurrentIndex = null;
	  this.mListener = null;
	  
	  if (document.getElementById && document.getElementById(prefix))
	    this.mContent = document.getElementById(prefix);
  }
  
  this.setPrefix = function(prefix)
  {
    this.mPrefix = prefix;    
  }

  this.getPrefix = function()
  {
    return this.mPrefix;
  }

  this.getIndex = function()
  {
    return this.mCurrentIndex;
  }
  
  this.addListener = function(fct) 
  {
    this.mListener = fct;
  }

  this.next = function()
  {
    if (this.mCurrentIndex != null)
	  	this.showContent(this.mCurrentIndex+1);
  }
  
  this.previous = function()
  {
    if (this.mCurrentIndex != null)
	  	this.showContent(this.mCurrentIndex-1);
  }

  this.showContent = function(index)
  {
	if (document.getElementById) {
	  var contentObj=document.getElementById(this.mPrefix+'_'+index);
	  if (contentObj && (index != this.mCurrentIndex) ) 
	  {

		// Show		
		this.mCurrentIndex = index;
		if (this.mListener == null || this.mListener(new DynamicContentEvent(this)) == true) {
			this.mContent.innerHTML = contentObj.innerHTML;
		}		
	  }
	}
  }

  this.__construct(prefix);
}

DynamicContentEvent = function(target)
{
  this.__construct = function(target) 
  {	  
	  this.mTarget = target;
  }
  
  this.getTarget = function()
  {
    return this.mTarget;
  }
  
  this.__construct(target);
}
