// CONTAINER CLASS
clsContainer.prototype = new clsComponent();
clsContainer.prototype.constructor = clsContainer;
clsContainer.superclass = clsComponent.prototype;

clsContainer.prototype.intChildMaxHeight = 0;

// --------------------------------------------------------------------
function clsContainer( strName ){ this.init( strName ); }

// --------------------------------------------------------------------
clsContainer.prototype.init = function( strName )
{ 
	clsContainer.superclass.init.call( this , strName );
	this.intClientWidth = xClientWidth();
	this.intClientHeight = xClientHeight();
	this.arrComponents = [];
	this.strAlign = "Left";
	
	clsComponent.prototype.arrContainers.push( this.strName );
	intCountContainers = clsComponent.prototype.arrContainers.length;
	
	this.intContainerIndex = intCountContainers - 1;
	this.intParentContainerIndex = intCountContainers - 2;
	this.strContainer = clsComponent.prototype.arrContainers[ this.intParentContainerIndex ];

	if( intCountContainers > 1 ){
		clsComponent.prototype.mapContainers[this.strName] = {};
		clsComponent.prototype.mapContainers[this.strName].intTop = Number(clsComponent.prototype.mapContainers[this.strContainer].intTop);
		clsComponent.prototype.mapContainers[this.strName].intMaxHeight = 0;
		//clsComponent.prototype.mapContainers[this.strName].intMaxHeight = Number(clsComponent.prototype.mapContainers[this.strContainer].intMaxHeight);
		clsComponent.prototype.mapContainers[this.strName].intLeft = Number(clsComponent.prototype.mapContainers[this.strContainer].intLeft);
		clsComponent.prototype.mapContainers[this.strName].intRelativeTop = 0;
		clsComponent.prototype.mapContainers[this.strName].arrGroupElems = [];
	} else {
		clsComponent.prototype.mapContainers[this.strName] = { intTop : 0 , intLeft : 0 , intMaxHeight : 0 , intRelativeTop : 0 , arrGroupElems : []};
	}
}

// --------------------------------------------------------------------
clsContainer.prototype.addComponent = function( strName ){ 
	this.arrComponents.push(strName);
	this[strName] = new clsComponent( strName ) ;
	this[strName].setContainer( this.strName );
}

// --------------------------------------------------------------------
clsContainer.prototype.addContainer = function( strName ){ 
	this[strName] = new clsContainer( strName ) ;
}

// --------------------------------------------------------------------
clsContainer.prototype.setAlign = function( strValue ){ 
	if( this.intContainerIndex > 0 ) return; 
	this.strAlign = strValue ;
}

// --------------------------------------------------------------------
clsContainer.prototype.setX = function( intValue ){ clsContainer.prototype.mapContainers[this.strName].intLeft = intValue ; }

// --------------------------------------------------------------------
clsContainer.prototype.getX = function(){ return this.intX; }

// --------------------------------------------------------------------
clsContainer.prototype.setup = function()
{
	if( this.intContainerIndex != 0 ) return;
	
	switch( this.strAlign )
	{
		case "Center" :
			intX = ( this.intClientWidth > this.intWidth )? Math.round( ( this.intClientWidth - this.intWidth ) / 2 ) : 0;
			this.setX( intX );
			//xAddEventListener(window, 'resize', this.onResize, false);
			break;
		case "Right" :
			intX = ( this.intClientWidth > this.intWidth )? this.intClientWidth - this.intWidth : 0;
			this.setX( intX );
			break;
	}
}

// --------------------------------------------------------------------
clsContainer.prototype.onResize = function (){ window.location.href = window.location.href; }

// --------------------------------------------------------------------
clsContainer.prototype.setChildMaxHeight = function( objDiv )
{ 
	if( objDiv.tagName == "Div" )
	{
		if( objDiv.attributes["id"] != null )
		{
			intHeight = xHeight( objDiv );
			if( this.intChildMaxHeight == 0 )
				this.intChildMaxHeight = intHeight;
			else
				this.intChildMaxHeight = Math.max( this.intChildMaxHeight , intHeight );
		}
		xTreeWalk( objDiv , this.setMaxChildHeight );
	}
}

// --------------------------------------------------------------------
clsContainer.prototype.setChildsSameHeight = function ()
{
	intMaxHeight = 0;
	for( intI=0; intI < this.arrComponents.length; intI++ )
	{
		oElem = xGetElementById( this.arrComponents[intI] );
		arrDivs = xGetElementsByTagName( "Div" , oElem );
		for( intY=0; intY < arrDivs.length; intY++ )
		{
			oDiv = arrDivs[intY];
			intNewHeight = xHeight(oDiv);
			intMaxHeight = Math.max( intMaxHeight , intNewHeight );
		}
	}
	for( intI=0; intI < this.arrComponents.length; intI++ )
	{
		oElem = xGetElementById( this.arrComponents[intI] );
		arrDivs = xGetElementsByTagName( "Div" , oElem );
		for( intY=0; intY < arrDivs.length; intY++ )
		{
			oDiv = arrDivs[intY];
			xHeight( oDiv , intMaxHeight );
		}
	}
	intMaxComponentHeight = 0;
	for( intI=0; intI < this.arrComponents.length; intI++ )
	{
		oElem = xGetElementById( this.arrComponents[intI] );
		intHeight = xHeight( oElem );
		clsComponent.prototype.mapContainers[this.strName].intMaxHeight = Math.max(intMaxComponentHeight,intHeight) ;
	}
}

// --------------------------------------------------------------------
clsContainer.prototype.display = function ()
{
	// objects
	if( this.intContainerIndex == 0 ) return;
	
	intContainerHeight = this.mapMargins.Top + clsComponent.prototype.mapContainers[this.strName].intRelativeTop + this.mapMargins.Bottom ;
	
	if( this.blnIncreaseContainerY == true )
	{
		if( this.getMaxHeight() == 0 ){
			this.addTop( intContainerHeight );
		} else {
			nMaxHeight = Math.max( intContainerHeight , this.getMaxHeight() );
			this.addTop( nMaxHeight );
			this.setMaxHeight( 0 );
		}
	} 
	else
	{
		if( this.getMaxHeight() > 0 )
		{
			oPrevHeight = this.getMaxHeight();
			nMaxHeight = Math.max( intContainerHeight , oPrevHeight );
			this.setMaxHeight( nMaxHeight );
		} else {
			this.setMaxHeight( intContainerHeight );
		}
		this.addGroupElem( this.strName );
	}
	
	clsComponent.prototype.arrContainers.pop();
	delete clsComponent.prototype.mapContainers[this.strName];
}
