// www.itelligent.com.mx, Agosto 2010

var bpage = {
    def : {
        opacity: .7,
        background: '#000',
        message: null
    },
    __interno: {
        overlay: null,
        message: null
    },
    show: function (options) {
        if(this.__interno.overlay != null)
            return false;

        if(!options)
            options = {};

        // complementar option sin reescribir
        for(a in this.def)
            if(!options[a])
                options[a] = this.def[a];

        this.__interno.overlay = $('<div style="background:' + options.background + '; opacity: ' + options.opacity + '; position: fixed; top: 0px; left: 0px; bottom: 0px; right: 0px; z-index: 101; width: 100%; height: 100%; "></div>')

        if(document.all) {
            $('body','html').css({
                height: '100%',
                width: '100%'
            });

            $('html').css('overflow', 'hidden');

            this.__interno.overlay.css({
                    'position' : 'absolute',
                    'filter' : 'alpha(opacity=' + (options.opacity*100) + ')',
                    'height':  Math.max(
                        Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
                        Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
                        Math.max(document.body.clientHeight, document.documentElement.clientHeight)
                    )
//    )((document.body.scrollHeight > $(document.body).innerHeight() ? document.body.scrollHeight : $(document.body).innerHeight())) + 'px'
                })
        }

        if(!options.message)
            options.message = $('<div style="background: url(scripts/loadingb.gif) center center no-repeat #000; border: 1px solid #888; width: 130px; height: 100px; "></div>');

        this.__interno.message = options.message;

        this.__interno.message.css({
            'z-index' : 103,
            'position': document.all ? 'absolute' : 'fixed',
            'top': '50%',
            'left': '50%'
        })

        $('body')
            .append(this.__interno.overlay)
            .append(this.__interno.message)

        this.__interno.message.css({
            'margin-left': (-1 * (Math.ceil(this.__interno.message.width() / 2))) + 'px',
            'margin-top': (-1 * (Math.ceil(this.__interno.message.height() / 2))) + 'px'
        })

        return true;
    },
    hideMessage: function () {
        this.__interno.message.hide();
    },
    showMessage: function () {
        this.__interno.message.show();
    },
    hide: function () {
        if(document.all) {
            $("body","html").css({height: "auto", width: "auto"});
            $("html").css("overflow","");
        }

        for(a in this.__interno)
            if(this.__interno[a]) {
                this.__interno[a].remove();
                this.__interno[a] = null;
            }

    }
}
