/*************************************************************************************
 Generalized shaded layers
 Requirements(s):
 - /js/global/jquery-1.4.min.js
 ************************************************************************************/

var shade = {
    isCreated: false,       /* keeps tabs if the shade layer was already created */
    shadeCount: 0,          /* keeps track of the number of times the shade was opened */

    createLayer: function() {
        if (!this.isCreated) {
            $(top.document.body).append('<div id="shadedLayer" style="display: none"></div>');
            var shadedLayer = $('#shadedLayer');

            shadedLayer.css({
                'z-index' : '10000',
                'position' : 'absolute',
                'top' : '0',
                'left' : '0',
                'width' : '100%',
                'height' : '100%',
                'background-color' : 'black'
            });

            this.isCreated = true;
        }
    },

    show: function() {
        this.createLayer();
        this.shadeCount++;

        var overlay = $('#shadedLayer');

        $(overlay).css("opacity", "0.5");
        $(overlay).css("height", $(document.body).height() + "px");
        $(overlay).fadeIn(1000);

        $(window).bind("resize", function() {
            shade.setsize($(window).width(), $("body").height());
        });
    },

    setsize: function(w, h) {
        $('#shadedLayer').css({
            width: w,
            height: h
        });
    },

    hide: function() {
        if (this.shadeCount == 1) {
            $("#shadedLayer").fadeOut(1000);
        }
        this.shadeCount--;
    }
};
