var pInit = null
window.onload   = window_onLoad;
window.onresize = window_onResize;

var MIN_WIDTH   = 490; //680;
var divPrincipal, divTitulo, divImagen, divContenido, divMenu, divFooter;

var	sAgent = navigator.userAgent;
var	bIsIE = sAgent.indexOf("MSIE") > -1;
var	bIsNav = sAgent.indexOf("Mozilla") > -1 && !bIsIE;


//alert ("bIsIE " + bIsIE );
//alert ("bIsNav " + bIsNav );
 
function window_onResize( objEvent ){ 
	if( objEvent ){window.location.href = window.location.href; return;} 
	updateMenuPosition( divPrincipal.getWidth(), getGlobalHeight());
} 

function window_onLoad( objEvent ){
	if( pInit != null ){
		pInit () 
	}
	divPrincipal= new iLayer("divPrincipal")
	divTitulo	= new iLayer("divTitulo")
	divImagen	= new iLayer("divImagen")
	divContenido= new iLayer("divContenido")
	divMenu		= new iLayer("divMenu")
	divFooter	= new iLayer("divFooter")
	if( objEvent ){
		w = divPrincipal.getWidth() + (bIsIE ? 10 : 0 );
		h = getGlobalHeight();
		divPrincipal.resize( w, h );
	}
	else{
		w = divPrincipal.getWidth();
		h = getGlobalHeight()
	}

	var wContenido = divContenido.getWidth();
//	alert (xx)
//	Si el ancho minimo es menor al ancho del contenido se actualiza el ancho del contenido.
	if (MIN_WIDTH < wContenido) MIN_WIDTH = wContenido + (bIsIE ? 10 : 0 );
	
	updateMenuPosition( w, h );
	divMenu.show();
	divFooter.show();
}

function getGlobalHeight(){
	var TotalHeigth  = divPrincipal.getHeight();
	TotalHeigth = ( divTitulo.getHeight() + divImagen.getHeight() + divContenido.getHeight() +  divFooter.getHeight()) > TotalHeigth ? 
			 divTitulo.getHeight() + divImagen.getHeight() + divContenido.getHeight() +  divFooter.getHeight() : TotalHeigth ;
	if (divPrincipal.getHeight() != TotalHeigth)
		TotalHeigth += 20;

	return TotalHeigth
}

function updateMenuPosition( width, height ){
	var w = width - divMenu.getWidth() - 2
	var h = height - divMenu.getY()
	if( w < MIN_WIDTH )
		w = MIN_WIDTH
	divMenu.setX( w );
	divMenu.setHeight( h );
	divFooter.move(50, h - (divFooter.getHeight()));
}