var EfluxMensajeEspera = function () {
	this.state = function () { return state(); }
	this.show = function () { show(); }
	this.hide = function () { hide(); }
	this.setTimeoutMilis = function (pMilis) { setTimeoutMilis(pMilis); }
	this.setImg = function (pImg) { setImg(pImg); }
	this.setSize = function (pW, pH) { setSize(pW, pH); }

	// ================ //

	var cCentrado = null;
	var cBloqueo = null;

	var cTimeout = null;
	var cImg = 'plantillas/default/img/wait.gif';

	var appendImg = function () {
		var bodys = document.getElementsByTagName('body');
		if (bodys && bodys.length>0) {
			var body = bodys[0];
			if (body) {
				var img = new Image();
				img.src = cImg;
				img.style.display = 'none';
				body.appendChild(img);
			}
		}
	}

	var initObjs = function () {
		if (cBloqueo==null) { cBloqueo = new EfluxBloquearContenido(); }
		if (cCentrado==null) {
			cCentrado = new EfluxMensajeCentrado();
			cCentrado.setSize(64, 64);
			cCentrado.setId('mensajeEspera');
		}
	}
	
	var getCentrado = function () {
		if (cCentrado==null) { initObjs(); }
		return cCentrado;
	}


	var getBloqueo = function () {
		if (cBloqueo==null) { initObjs(); }
		return cBloqueo;
	}

	var state = function () { return getBloqueo().state(); }
	var show = function () {
		getBloqueo().reshow();
		getCentrado().reshow('<img src="'+ cImg +'"/>');
	}
	var hide = function () {
		if (cTimeout==null) {
			getBloqueo().hide();
			getCentrado().hide();
		} else {
			setTimeout(function() { getBloqueo().hide(); getCentrado().hide(); },
				cTimeout);
		}
	}
	var setTimeoutMilis = function (pMilis) {
		cTimeout = pMilis;
	}
	var setImg = function (pImg) {
		cImg = pImg;
		appendImg();
	}
	var setSize = function (pW, pH) {
		getCentrado().setSize(pW, pH);
	}
	
	appendImg();
}

// AUTOCARGA DE DEPENDENCIAS
new function () {
	var DEPENDENCIAS = [
		'EfluxBloquearContenido',
		'EfluxMensajeCentrado'
		];
	var dir = 'js';
	if (typeof EFLUX_JS_DIR != 'undefined') { dir = EFLUX_JS_DIR; }

	for (var i=0; i<DEPENDENCIAS.length; ++i) {
		var d = DEPENDENCIAS[i];
		var js = dir +'/'+ d +'/'+ d +'.js';
		try { eval ('new '+ d +'()'); }
		catch (e) {
			document.writeln('<SCRIPT src="'+ js +'"></SCRIPT>');
		}
	}
}

