// Component CLASS
function clsComponent( strName ){
	if ( arguments.length > 0 )
		this.init( strName );
}

clsComponent.prototype.mapContainers = {};
clsComponent.prototype.arrContainers = [];

clsComponent.prototype.init = function( strName )
{
	this.strName = strName;
	this.strContainer = "";
	this.intX = 0;
	this.intY = 0;
	this.intWidth = 0;
	this.intHeight = 0;
	this.mapMargins = { Top : 0 ,  Bottom : 0 , Left : 0 , Right : 0 };
	this.blnIncreaseContainerY = true;
}

clsComponent.prototype.setContainer = function( strValue ){ this.strContainer = strValue ; }
clsComponent.prototype.getContainer = function(){ return this.strContainer; }

clsComponent.prototype.setX = function( intValue ){ this.intX = intValue ; }
clsComponent.prototype.getX = function(){ return this.intX; }

clsComponent.prototype.setY = function( intValue ){ this.intY = intValue ; }
clsComponent.prototype.getY = function(){ return this.intY; }

clsComponent.prototype.setWidth = function( intValue ){ this.intWidth = intValue ; }
clsComponent.prototype.getWidth = function(){ return this.intWidth; }

clsComponent.prototype.setHeight = function( intValue ){ this.intHeight = intValue ; }
clsComponent.prototype.getHeight = function(){ return this.intHeight; }

clsComponent.prototype.setMargin = function( strMargin , intValue ){ this.mapMargins[strMargin] = intValue ; }
clsComponent.prototype.getMargin = function( strMargin ){ return this.mapMargins[strMargin]; }

clsComponent.prototype.setIncreaseContainerY = function( blnValue ){ this.blnIncreaseContainerY = blnValue; }
clsComponent.prototype.getIncreaseContainerY = function(){ return this.blnIncreaseContainerY; }

clsComponent.prototype.setTop = function( intValue ){ 
	clsComponent.prototype.mapContainers[this.strContainer].intTop = intValue; 
	clsComponent.prototype.mapContainers[this.strContainer].intRelativeTop = intValue; 
}
clsComponent.prototype.addTop = function( intValue ){ 
	clsComponent.prototype.mapContainers[this.strContainer].intTop += intValue;
	clsComponent.prototype.mapContainers[this.strContainer].intRelativeTop += intValue;
}
clsComponent.prototype.subTop = function( intValue ){ 
	clsComponent.prototype.mapContainers[this.strContainer].intTop -= intValue;
	clsComponent.prototype.mapContainers[this.strContainer].intRelativeTop -= intValue;
}
clsComponent.prototype.getTop = function( strName ){ return clsComponent.prototype.mapContainers[this.strContainer].intTop; }

clsComponent.prototype.setLeft = function( intValue ){ clsComponent.prototype.mapContainers[this.strContainer].intLeft = intValue; }
clsComponent.prototype.getLeft = function(){ return clsComponent.prototype.mapContainers[this.strContainer].intLeft; }

clsComponent.prototype.setMaxHeight = function( intValue ){ clsComponent.prototype.mapContainers[this.strContainer].intMaxHeight = intValue; }
clsComponent.prototype.getMaxHeight = function(){ return clsComponent.prototype.mapContainers[this.strContainer].intMaxHeight; }

clsComponent.prototype.addGroupElem = function( strValue ){ clsComponent.prototype.mapContainers[this.strContainer].arrGroupElems.push( strValue ); }
clsComponent.prototype.getGroupElems = function(){ return clsComponent.prototype.mapContainers[this.strContainer].arrGroupElems; }
clsComponent.prototype.getGroupElemAt = function( intIndex ){ return clsComponent.prototype.mapContainers[this.strContainer].arrGroupElems[intIndex]; }

clsComponent.prototype.display = function ()
{
	// recupero l'elemento
	oElem = xGetElementById( this.strName );

	// imposto la larghezza se impostata
	if( this.intWidth > 0 ) 
		xWidth( oElem, this.intWidth );
	
	// imposto l'altezza se impostata
	if( this.intHeight > 0 ) 
		xHeight( oElem, this.intHeight );
		
	// imposto l'y
	xTop( oElem, this.getTop() + this.mapMargins.Top );
	
	// imposto la x
	xLeft( oElem, this.getLeft() + this.mapMargins.Left + this.intX );

	// imposto lo z-index
	if( this.ZIndex > 0 ) 
		xZIndex( oElem, this.ZIndex );
		
	// se è l'ultima zona del livello ...
	if( this.blnIncreaseContainerY == true )
	{
		// sommo margine alto, altezza, margine basso
		intElemHeight = this.mapMargins.Top + xHeight(oElem) + this.mapMargins.Bottom ;

		// se l'altezza dell' elemento precedente è zero ...
		if( this.getMaxHeight() == 0 ){
			// aggiungo l'altezza dell'elemento
			this.addTop( intElemHeight );
		// se esiste già un'altezza impostata dall'elemento precedente ...
		} else {
			// calcolo l'altezza maggiore
			nMaxHeight = Math.max( intElemHeight , this.getMaxHeight() );
			// imposto l'altezza negli elementi precedenti
			xHeight( oElem, nMaxHeight );
			for( intI=0; intI < this.getGroupElems().length; intI++ )
				xHeight( this.getGroupElemAt( intI ) , nMaxHeight );
			this.addTop( nMaxHeight );
			this.setMaxHeight( 0 );
		}
	} 
	else
	{
		if( this.getMaxHeight() > 0 )
		{
			oPrevHeight = this.getMaxHeight();
			nMaxHeight = Math.max( xHeight( oElem ) , oPrevHeight ); 
			this.setMaxHeight( nMaxHeight );
		} else {
			this.setMaxHeight( xHeight( oElem ) );
		}
		this.addGroupElem( this.strName );
	}
	// show
	
	xShow( oElem );
}
