﻿/// <summary>
/// Mostra tela preta por trás do elemento, desabilitando todos os outros
/// </summary>
var documentDisabler = {
    arr : [],
    /// <summary>
    /// Adiciona
    /// </summary>
    /// <param name="ID" >Identificação única para o disabler</param>
    /// <param name="obj" >O objeto que será habilitado para que os outros sejam desabilitados</param>
    add : function(ID, obj){
        var dis = document.createElement("DIV");
        dis.style.zIndex = (obj.style != null && obj.style.zIndex != null && !isNaN(obj.style.zIndex)) ? parseInt(obj.style.zIndex) - 2 : 0;
        dis.style.position = "absolute";
        dis.style.left = "0px";
        dis.style.top = "0px";
        dis.style.backgroundColor = "#000000";
        fade(dis,50);
        dis.style.width = InnerSize()[0] + "px";
        dis.style.height = InnerSize()[1] + "px";
		
        document.body.appendChild(dis);
        this.arr.push({"ID" : ID, "OBJ" : dis});
        this.addEventResize();
        dis = null;
        obj = null;
        //__page.mapa.hide();
    },
    /// <summary>
    /// Remove
    /// </summary>
    /// <param name="ID" >Identificação única do disabler</param>
    remove : function(ID){
        //__page.mapa.show();
        for(var i = 0; i < this.arr.length; i++){
            if(this.arr[i].ID == ID){
                
                document.body.removeChild(this.arr[i].OBJ);
                
                this.arr.removeItems(this.arr[i]);
            }
        }
        this.addEventResize();
    },
    addEventResize : function(){
        removeEvent(window, "resize", evtResize);        
        if(this.arr.length > 0){

            addEvent(window, "resize", evtResize);        
        }
    }
};

function evtResize(){
    for(var i = 0; i < documentDisabler.arr.length; i++){
        var obj = documentDisabler.arr[i].OBJ;
        var size = InnerSize();
        var w = size[0];
        var h = size[1];
        
        obj.style.width = (w > 1000) ? w + "px" : "1000px";
        obj.style.height = (h > 500) ? h + "px" : "500px";
        obj = null;
    }
}