﻿if (!window.Windows)
    window.Windows = {};


Windows.FloatDiv = function() {
    this.currentDiv = null;
    this.width = 0;
    this.height = 0;
}

Windows.CreateDelegate = function(instance, method) {
    return function() {
        return method.apply(instance, arguments);
    }
}

Windows.FloatDiv.prototype = {
    BuildDimmerDiv: function() {
        document.write('<div id="dimmer" class="dimmer" style="width:0px; height:0px"></div>');
    },

    ShowBackground: function() {
        if (!this.currentDiv) {
        }
        var dimmer = $('#dimmer');
        var clientBounds = $common.getClientBounds();
        var clientWidth = clientBounds.width;
        var clientHeight = clientBounds.height;
        var dimWidth = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), clientWidth) + 'px';
        var dimHeight = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), clientHeight) + 'px';

        dimmer.width(dimWidth);
        dimmer.height(dimHeight);
        dimmer.css("visibility", "visible");
    },

    MoveToCenter: function() {
        if (!this.currentDiv)
            return;
        this.ShowBackground();
        var left = ($(window).width() - this.width) / 2;
        var top = ($(window).height() - this.height) / 2;
        this.currentDiv.css("left", left + 'px');
        this.currentDiv.css("top", top + 'px');

    },

    DisplayFloatingDiv: function(divId, cWidth, cHeight) {

        this.currentDiv = $('#' + divId);
        this.width = cWidth;
        this.height = cHeight;
        this.currentDiv.width(this.width);
        this.currentDiv.height(this.height);
        this.MoveToCenter();
        this.currentDiv.attr("class", 'dimming');
        this.currentDiv.css("visibility", "visible");
    },


    HiddenFloatingDiv: function() {
        if (!this.currentDiv)
            return;
        this.currentDiv.html(this.originalDivHTML);
        this.currentDiv.css("visibility", "hidden");
        $('#dimmer').css("visibility", "hidden");
        this.currentDiv = null;
    },

    Resize: function() {
        if (!this.currentDiv) {
        }
        this.ShowBackground();
    },

    Init: function() {

        $(window).resize(function() { divHandler.MoveToCenter(); });

        // used to dim the page
        this.BuildDimmerDiv();

    }
}

var divHandler = null;
if (!divHandler) {
    divHandler = new Windows.FloatDiv();
    divHandler.Init();
}
