﻿function scrollOffsetX() {
    return window.pageXOffset ?
                window.pageXOffset : document.documentElement.scrollLeft ?
                    document.documentElement.scrollLeft : document.body.scrollLeft;
}

function scrollOffsetY() {
    return window.pageYOffset ?
                window.pageYOffset : document.documentElement.scrollTop ?
                    document.documentElement.scrollTop : document.body.scrollTop;
}

function screenWidth() {
    return document.innerWidth ?
                document.innerWidth : document.documentElement.clientWidth ?
                    document.documentElement.clientWidth : document.body.clientWidth;
}

function screenHeight() {
    return document.body.clientHeight;
}

function windowScrolling() {
    if ($(".PopupPanel").length > 0) {
        var popupX = Math.round((screenWidth() - $('.PopupPanel')[0].offsetWidth) / 2 + scrollOffsetX());
        var popupY = Math.round((screenHeight() - $('.PopupPanel')[0].offsetHeight) / 2 + scrollOffsetY());
        $(".PopupPanel").css(
            {
                "left": popupX + "px",
                "top": popupY + "px",
                "z-index": "100"
            }
        );
        $(".__flash_wrapper").css(
            {
                "left": popupX + "px",
                "top": popupY + "px",
                "z-index": "101"
            }
        );
    }
}

window.onscroll = windowScrolling;
window.onresize = windowScrolling;