﻿jQuery.fn.center = function () {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    return this;
}

function make_modal(backgroundSel, panelSel) {
    var background = $(backgroundSel);
    if (background == undefined) {
        return;
    }

    background.css("left", "0");
    background.css("top", "0");
    background.css("height", screen.availHeight);
    background.css("width", screen.availWidth);

    $(panelSel).each(function () {
        panel = $(this);
        panel.center();
        panel.focus();
//        var mouseIsDown = false;
//        var leftD = 0;
//        var topD = 0;
//        panel.mousedown(function (kmouse) {
//            leftD = kmouse.pageX - panel.offset().left;
//            topD = kmouse.pageY - panel.offset().top;
//            panel.css("cursor", "move");
//            mouseIsDown = true;
//        });

//        panel.mouseup(function () {
//            panel.css("cursor", "default");
//            mouseIsDown = false;
//        });
//        panel.mousemove(function (kmouse) {
//            if (mouseIsDown) {
//                panel.css({ left: kmouse.pageX - leftD, top: kmouse.pageY - topD });
//            }
//        });
    });
};

$(document).ready(function () {
    make_modal(".message-panel", ".popup-message");
});

// для UpdatePannel
var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(function () {
    make_modal(".message-panel", ".popup-message");
});

