﻿//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(backgroundPopup, popupContact) {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#" + backgroundPopup).css({
            "opacity": "0.7"
        });
        $("#" + backgroundPopup).fadeIn("slow");
        $("#" + popupContact).fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup(backgroundPopup, popupContact) {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#" + backgroundPopup).fadeOut("slow");
        $("#" + popupContact).fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup(backgroundPopup, popupContact) {
    //request data for centering
    var pageSize = getPageSize();
    var pagewidth = pageSize[0];
    var pageheight = pageSize[1];

    var windowWidth = pagewidth;
    var windowHeight = pageheight;

    //centering
    $("#" + popupContact).css({
        "position": "absolute",
        "top": "50%",
        "left": "50%",
        "marginTop": 0 - (450 / 2),
        "marginLeft":0 - (500 / 2)
    });

    //only need force for IE6
    $("#" + backgroundPopup).css({
        "width": windowWidth,
        "height": windowHeight
    });

}

function getPageSize() {
    if (window.innerHeight && window.scrollMaxY) {
        // Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight) {
        // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    }
    else {
        // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
    }

    arrayPageSizeWithScroll = new Array(xWithScroll, yWithScroll);
    return arrayPageSizeWithScroll;
}     
