﻿var popupVoorwaardenStatus = 0;

function loadVoorwaardenPopup() {
    if (popupVoorwaardenStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupVoorwaarden").fadeIn("slow");
        popupVoorwaardenStatus = 1;
    }
}

function disableVoorwaardenPopup() {
    if (popupVoorwaardenStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        $("#popupVoorwaarden").fadeOut("slow");
        popupVoorwaardenStatus = 0;
    }
}

function centerVoorwaardenPopup() {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupVoorwaarden").height();
    var popupWidth = $("#popupVoorwaarden").width();
    $("#popupVoorwaarden").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {

    //LOADING POPUP
    //Click the button event!
    $("#divVoorwaarden").click(function() {
        centerVoorwaardenPopup();
        loadVoorwaardenPopup();
    });

    $("#popupVoorwaardenClose").click(function() {
        disableVoorwaardenPopup();
    });

    $("#popupVoorwaardenClose2").click(function() {
        disableVoorwaardenPopup();
    });

    $("#backgroundPopup").click(function() {
        disableVoorwaardenPopup();
    });
    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupVoorwaardenStatus == 1) {
            disableVoorwaardenPopup();
        }
    });
});