//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var SaveCartpopupStatus = 0;

//loading popup with jQuery magic!
function SaveCartloadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#SaveCartbackgroundPopup").css({
            "opacity": "0.7"
        });
        $("#SaveCartbackgroundPopup").fadeIn("slow");
        $("#SaveCartpopupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function SaveCartdisablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#SaveCartbackgroundPopup").fadeOut("slow");
        $("#SaveCartpopupContact").fadeOut("slow");
        popupStatus = 0;
    }
}
//centering popup
function SaveCartcenterPopup(x, y) {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#SaveCartpopupContact").height();
    var popupWidth = $("#SaveCartpopupContact").width();
    //centering
    $("#SaveCartpopupContact").css({
        "position": "absolute",
        "top": y - (popupHeight / 2),
        "left": x - 100
    });
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });
}




//loading popup with jQuery magic!
function AirTimeloadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#AirTimebackgroundPopup").css({
            "opacity": "0.7"
        });
        $("#AirTimebackgroundPopup").fadeIn("slow");
        $("#AirTimepopupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function AirTimedisablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#AirTimebackgroundPopup").fadeOut("slow");
        $("#AirTimepopupContact").fadeOut("slow");
        popupStatus = 0;
    }
}
//centering popup
function AirTimecenterPopup(x,y) {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#AirTimepopupContact").height();
    var popupWidth = $("#AirTimepopupContact").width();
    //centering
    $("#AirTimepopupContact").css({
        "position": "absolute",
        "top": y - (popupHeight/2),
         "left": x - 100
    });
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });
}

//loading popup with jQuery magic!
function RentalloadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#RentalbackgroundPopup").css({
            "opacity": "0.7"
        });
        $("#RentalbackgroundPopup").fadeIn("slow");
        $("#RentalpopupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function RentaldisablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#RentalbackgroundPopup").fadeOut("slow");
        $("#RentalpopupContact").fadeOut("slow");
        popupStatus = 0;
    }
}
//centering popup
function RentalcenterPopup() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#RentalpopupContact").height();
    var popupWidth = $("#RentalpopupContact").width();
    //centering
    $("#RentalpopupContact").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });
}

var event_x = 0;
var event_y = 0;
//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {



    $("a").click(function(e) {
        //   event_x = e.pageX;
        //  event_y = e.pageY;
        if ($(this).attr("class") == "popper") {
            AirTimecenterPopup(e.pageX, e.pageY);
            AirTimeloadPopup();
        }
    });


    //Airtime POPUP
    //  $("#AirTimebutton").click(function(e) {
    //let's try to get the curent x,y position.
    //centering with css
    //    AirTimecenterPopup(e.pageX, e.pageY);
    //load popup
    //  AirTimeloadPopup();
    //});


    $("#AirTimepopupContactClose").click(function() {
        AirTimedisablePopup();
    });
    $("#AirTimebackgroundPopup").click(function() {
        AirTimedisablePopup();
    });


    //Rental Popup
    $("#Rentalbutton").click(function() {
        //centering with css
        RentalcenterPopup();
        //load popup
        RentalloadPopup();
    });
    $("#RentalpopupContactClose").click(function() {
        RentaldisablePopup();
    });
    $("#RentalbackgroundPopup").click(function() {
        RentaldisablePopup();
    });

    //Save Cart popup
    $("#SaveCartbutton").click(function() {
        //centering with css
        SaveCartcenterPopup();
        //load popup
        SaveCartloadPopup();
   
    });

    $("#SaveCartpopupContactClose").click(function() {
        RentaldisablePopup();
    });

    $("#SaveCartbackgroundPopup").click(function() {
        SaveCartdisablePopup();
    });

    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            //AirTimedisablePopup();
            //RentaldisablePopup();
        }
    });

});