/*
*Autor: Flying Peach
*Copyright: 2009 Contenidos Digitales Interactivos FP S.C.
*Versión: 1.0
*/

namespace("FlyingPeach.WebBrowsers");

//INFO: La siguiente función crea N objectos cuyos nombres son equivalentes a los nombres
//del crearNamespace "nombre" definido como <nombre1>.<nombre2>.<...>.<nombreN>. Los objetos creados
//SIMULAN la existencia de la estructura crearNamespace.
function namespace(nombre) {
    var nombres = nombre.split(".");
    var nombreActual = window;
    for (var indiceNombre = 0; indiceNombre < nombres.length; indiceNombre++) {
        if (nombreActual[nombres[indiceNombre]] == null)
            nombreActual[nombres[indiceNombre]] = new Object();

        nombreActual = nombreActual[nombres[indiceNombre]];
    }
}

FlyingPeach.WebBrowsers.namespace = function(nombre) {
    namespace(nombre);
}

FlyingPeach.WebBrowsers.crearEvento = function(nombre) {
    return { nombre: nombre,
        handlers: new Array(),
        suscribirHandler: function(handler) {
            this.handlers.push(handler);
        },
        invocarHandlers: function(args) {
        try {
            //INFO: En el siguiente ciclo se usa un "for" convencional y no un "for (in)" debido a un bug con
            //el tipo de dato del iterador en este último tipo de ciclo.
                for (var indiceHandler = 0; indiceHandler < this.handlers.length; indiceHandler++)
                    this.handlers[indiceHandler](args);
            }
            catch (e) { alert(e); }
        }
    };
}

//INFO: Diseñada para ser invocada en el evento "onload" de "body", en caso de requerir mostrar overlays fullscreen.
FlyingPeach.WebBrowsers.inicializarOverlayFullScreen = function() {
    var hostOverlayFullScreen = null;
    if ((hostOverlayFullScreen = document.getElementById("hostOverlayFullScreen")) == null) {
        document.body.innerHTML = "<div id='hostOverlayFullScreen'></div>" + document.body.innerHTML;
    }
}

FlyingPeach.WebBrowsers.mostrarOverlayFullScreen = function(html, opacidad, color, textoBotonOcultar) {
    opacidad = opacidad == null ? .75 : opacidad;
    color = color == null ? "#000000" : color;
    textoBotonOcultar = textoBotonOcultar == null ? "Regresar" : invocarAsincronamente;
    var backgroundOverlay = null;
    var foregroundOverlay = null;
    //INFO: Instrucción no necesaria si se invoca "inicializarOverlayFullScreen" en el evento "onload" de "body".
    //Esta instrucción produce el recargado de la página host si no se invoca "inicializarOverlayFullScreen" en 
    //el evento "onload" de "body".
    FlyingPeach.WebBrowsers.inicializarOverlayFullScreen();
    document.getElementById("hostOverlayFullScreen").innerHTML = "<div id='backgroundOverlay' style='z-index: 10000; filter: alpha(opacity=" + (opacidad * 100) + "); opacity: " + opacidad + "; background-color: " + color + "; position: absolute; top: 0px; left: 0px; width: 105%; height: 100%;'><table width='100%' height='100%' ><tr><td align='center' valign='middle' width='100%' height='100%'>&nbsp</td></tr></table></div>" + "<div id='foregroundOverlay' style='z-index: 10001; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;'><table width='100%' height='100%' ><tr><td align='center' valign='middle' width='100%' height='100%'><a id='botonOcultarOverlay' href='#' onclick='return FlyingPeach.WebBrowsers.ocultarOverlayFullScreen();'>" + textoBotonOcultar + "</a>" + html + "</td></tr></table></div>" + document.body.innerHTML;
}

FlyingPeach.WebBrowsers.ocultarOverlayFullScreen = function() {
    var hostOverlayFullScreen = null;
    if ((hostOverlayFullScreen = document.getElementById("hostOverlayFullScreen")) != null)
        hostOverlayFullScreen.innerHTML = "";

    return false;
}