﻿var Curtain = {
    GetInnerWindowSize: function() {
        return {
            w: window.innerWidth || document.documentElement.clientWidth,
            h: window.innerHeight || document.documentElement.clientHeight
        };
    },
    GetDocumentSize: function() {
        return {
            w: document.body.scrollWidth,
            h: document.body.scrollHeight
        };
    },
    Resize: function(fix) {
        var divCurtain = $('#divCurtain')[0];
        var scd = { w: document.documentElement.clientWidth, h: document.documentElement.clientHeight };
        var dimsJanela = Curtain.GetInnerWindowSize();
        var dimsDoc = Curtain.GetDocumentSize();
        with (divCurtain.style) {
            width = (dimsDoc.w) + 'px';
            height = (dimsDoc.h) + 'px';
            top = '0px';
            left = '0px';
            zIndex = 999;
        }
        //if (!fix) setTimeout('Curtain.Resize(true)', 10);
    },
    Hide: function() {
        var divCurtain = $('#divCurtain');
        if (divCurtain.length > 0)
            divCurtain.fadeOut('slow');
    },
    Show: function() {
        var divCurtain = $('#divCurtain');
        if (divCurtain.length == 0) {
            divCurtain = document.createElement('div');
            divCurtain.id = 'divCurtain';
            with (divCurtain.style) {
                position = 'absolute';
                top = '0px';
                left = '0px';
                backgroundColor = 'black';
                display = 'none';
            }
            document.body.appendChild(divCurtain);
            Curtain.Resize();
            $(window).resize(function() {
                setTimeout('Curtain.Resize(false);', 10);
            });
            $(window).scroll(function() {
                setTimeout('Curtain.Resize(false);', 10);
            });
        }
        $('#divCurtain').fadeTo('slow', 0.8);
    }
};
var LightWindow = {
    ActiveID: null,
    Close: function() {
        if (LightWindow.ActiveID == null) return;
        var div = $('#' + LightWindow.ActiveID);
        if (div.length > 0)
            div.fadeOut('fast');
        Curtain.Hide();
    },
    ShowDiv: function(divID) {
        var div = $('#' + divID)[0];
        div.parentNode.removeChild(div);
        LightWindow.ShowElement(div);
    },
    ShowContent: function(content, divWidth, divHeight) {
        var div = $('#divContentLightWindow');
        with (div.style) {
            position = 'absolute';
            top = '0px';
            left = '0px';
            backgroundColor = 'white';
            display = 'none';
            width = divWidth + 'px';
            height = divHeight + 'px';
        }
        div.innerHTML = content;
        LightWindow.ShowElement(div);
    },
    Center: function() {
        if (LightWindow.ActiveID == null) return;
        var div = $('#' + LightWindow.ActiveID)[0];
        var dimsJanela = Curtain.GetInnerWindowSize();
        var dimsMsgBox = {
            w: div.offsetWidth,
            h: div.offsetHeight
        };
        var pos = { x: Math.floor((dimsJanela.w - dimsMsgBox.w) / 2), y: Math.floor((dimsJanela.h - dimsMsgBox.h) / 2) };
        pos.y += Math.max(document.documentElement ? document.documentElement.scrollTop : 0, document.body ? document.body.scrollTop : 0);
        div.style.left = pos.x + 'px';
        div.style.top = pos.y + 'px';
    },
    ShowElement: function(element) {
        var dimsJanela = Curtain.GetInnerWindowSize();
        Curtain.Show();
        document.body.appendChild(element);
        with (element.style) {
            display = 'block';
            position = 'absolute';
            zIndex = 9999;
        }
        LightWindow.ActiveID = element.id;
        LightWindow.Center();
        $(window).resize(function() {
            setTimeout('LightWindow.Center();', 10);
        });
        $(window).scroll(function() {
            setTimeout('LightWindow.Center();', 10);
        });
    }
};
var lightbox = {
    abrirJanela: function(nome)
    {
        if (nome == 'conf_adicionado')
        {
            MsgBox.Show('Adicionar imóvel aos favoritos','Imóvel adicionado com sucesso', {Sim:false,Nao:false,Ok:true});
        }
        else if (nome == 'conf_removido')
        {
            MsgBox.Show('Remover imóvel dos favoritos','Imóvel removido com sucesso', {Sim:false,Nao:false,Ok:true});
        }
    }
} //TODO: Utilizar somente nova função