var Win = {
    elementos: null,
    init: function (sombra, contenido, cabecera, cuerpo) {
        this.elementos = {
            sombra: sombra,
            contenido: contenido,
            cabecera: cabecera,
            titulo: $(document.createElement('div')).attr('class', 'titulo'),
            cuerpo: cuerpo,
            ventana: $(document.createElement('iframe'))
        };
        this.elementos.cabecera.append( $( document.createElement('div') ).bind('click', Win.clouse).attr({'class':'clouse', 'title':'Clic aquí o teclee Esc para cerrar esta ventana.'}) )
                               .append( this.elementos.titulo )
        this.elementos.cuerpo.append( this.elementos.ventana );

        return this;
    },
    show : function ( title, url ) {

        Win.elementos.ventana.hide().load(function (){
            Win.elementos.ventana.show();
        }).attr('src', url);
        Win.elementos.titulo.html(title || '');

        // se establece que el body y el html adquieran la dimensión de la ventana 100%
        $('body', 'html ').css({
            'height'    : '100%',
            'width'     : '100%',
            'overflow'  : 'hidden'
        });
        
        // no permite scroll al ver el cuadro
        $(window).scroll(function () { $(window).scrollTop(0); });
        $(window).attr('scroll', false);

        // se controla la redimensión
        $(window).bind('resize', function () {
            Win.elementos.sombra.show().css({
                'height'    : $('body').height(),
                'width'     : $('body').width()
            });
        }).scrollTop(0);
        
        // se le da a la sombra la dimensión del body
        Win.elementos.sombra.show().css({
            'height'    : $('body').height(),
            'width'     : $('body').width()
        });

        Win.elementos.contenido.slideDown('slow', function () {});

        $(document).bind('keypress', function (e) {
            var code = new Number(e.keyCode);
            if (code.valueOf() === 27) {
                Win.clouse();
            }
        });
    },
    clouse : function () {
        $(document).unbind('keypress');
        Win.elementos.ventana.unbind('load');
        Win.elementos.contenido.slideUp('slow', function () {
            // se regresan la medidas del html y body
            $('body', 'html ').css({
                'height'    : 'auto',
                'width'     : 'auto',
                'overflow'  : 'auto'
            });

            Win.elementos.sombra.hide();

            Win.elementos.ventana.attr('src', 'black');

            $(window).attr('scroll', true);
            $(window).unbind('resize');
            $(window).unbind('scroll');
        });
    }
};