var pInit = null
window.onload   = window_onLoad;
window.onresize = window_onResize;

var MIN_WIDTH   = 479;
var objDivMain;
var objDivMenu;
var Content1, Content2, Content3, Content4, ContentAux;
var ToolBar;
var objMenuCont;
var objMenu;

function window_onResize( objEvent ){ 
	if( objEvent ){window.location.href = window.location.href; return;} 
	updateMenuPosition( objDivMain.getWidth(), getGlobalHeight());
} 

function window_onLoad( objEvent ){
	if( pInit != null ){
		pInit () 
	}
	
	PrecargarMenuImages()
	Content1	= new iLayer("Content1")
	Content2	= new iLayer("Content2")
	Content3	= new iLayer("Content3")
	ContentAux	= new iLayer("ContentAux")
	//ebc ToolBar	= new iLayer("ToolBar")
	
	
	objDivMain	= new iLayer("Template")
	
	objDivMenu	= new iLayer("divRightSide")
	
	objMenu	= new iLayer("layerMenu")
	objMenuCont = new iLayer("divMenuContent")
	//ebc Bottom= ToolBar.getHeight()

	if( objEvent ){
		w = objDivMain.getWidth() + 10;
		h = getGlobalHeight();
		objDivMain.resize( w, h );
	}
	else{
		
		w = objDivMain.getWidth()
		h = getGlobalHeight()
	}
	updateMenuPosition( w, h );
	objDivMenu.show();
	//ebc ToolBar.show();
	init();
}

function getGlobalHeight(){
	var TotalHeigth = objDivMain.getHeight()

/*ebc 	TotalHeigth = ( Content1.getHeight() + 168 + Bottom ) > TotalHeigth ? 
			  Content1.getHeight() + 168 + Bottom : TotalHeigth ;
	TotalHeigth = ( Content2.getHeight() + 168 + Bottom ) > TotalHeigth ? 
			  Content2.getHeight() + 168 + Bottom: TotalHeigth ;
	TotalHeigth = ( Content3.getHeight() + 404 + Bottom ) > TotalHeigth ? 
			  Content3.getHeight() + 404 + Bottom: TotalHeigth ;
	TotalHeigth = ( ContentAux.getHeight() + 404 + Bottom ) > TotalHeigth ? 
			  ContentAux.getHeight() + 404 + Bottom: TotalHeigth ;
			  */
	TotalHeigth = ( Content1.getHeight() + 80) > TotalHeigth ? 
			  Content1.getHeight() + 80 : TotalHeigth ;
	
/*	TotalHeigth = ( Content2.getHeight() + 168  ) > TotalHeigth ? 
			//  Content2.getHeight() + 168 : TotalHeigth ;
	TotalHeigth = ( Content3.getHeight() + 404 ) > TotalHeigth ? 
			//  Content3.getHeight() + 404 : TotalHeigth ;
	TotalHeigth = ( ContentAux.getHeight() + 404 ) > TotalHeigth ? 
			//  ContentAux.getHeight() + 404 : TotalHeigth ;
*/

	if (objDivMain.getHeight() != TotalHeigth)
		TotalHeigth += 20
		
	
	return TotalHeigth
}

function updateMenuPosition( width, height ){
	
	var w = width - objDivMenu.getWidth() - 2
	var h = height - objDivMenu.getY()
	
	if( w < MIN_WIDTH )
		w = MIN_WIDTH

	
	objDivMenu.setX( w )
	objDivMenu.setHeight( h)

	//redrawBgFill( h )

	//ebc ToolBar.move(0, h - (ToolBar.getHeight()))


	objMenu.setHeight( h - 92)
	objMenuCont.setHeight( h - 92  )
	

}

function redrawBgFill( h ){
	MM_setTextOfLayer( "divMenuBgFill", "", "<img src='/img/sp.gif' width='10' height='" + h + "'>" )
}

function ShowLayerAux(intLeft, intTop, intHeight, intWidth){
	with(ContentAux){
		setX(intLeft);
		setY(intTop);
		setWidth(intWidth);
		setHeight(intHeight);
		show();
	}
}
