﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com				
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopupGood() {
    //loads popup only if it is disabled

    if (popupStatus == 0) {
        $("#backgroundPopupGood").css({
            "opacity": "0.7"
        });
        $("#backgroundPopupGood").fadeIn("slow");
        $("#popupContactGood").fadeIn("slow");
        popupStatus = 1;
    }
}

//loading popup with jQuery magic!
function loadPopupAverage() {
    //loads popup only if it is disabled

    if (popupStatus == 0) { 
            $("#backgroundPopupAverage").css({
                "opacity": "0.7"
            });
            $("#backgroundPopupAverage").fadeIn("slow");
            $("#popupContactAverage").fadeIn("slow");
            popupStatus = 1;
    }
}

//loading popup with jQuery magic!
function loadPopupPoor() {
    //loads popup only if it is disabled

    if (popupStatus == 0) {
        $("#backgroundPopupPoor").css({
            "opacity": "0.7"
        });
        $("#backgroundPopupPoor").fadeIn("slow");
        $("#popupContactPoor").fadeIn("slow");
        popupStatus = 1;
    }
}

//loading popup with jQuery magic!
function loadPopupPolish() {
    //loads popup only if it is disabled

    if (popupStatus == 0) {
        $("#backgroundPopupPolish").css({
            "opacity": "0.7"
        });
        $("#backgroundPopupPolish").fadeIn("slow");
        $("#popupContactPolish").fadeIn("slow");
        popupStatus = 1;
    }
}

//loading popup with jQuery magic!
function loadPopupPortuguese() {
    //loads popup only if it is disabled

    if (popupStatus == 0) {
        $("#backgroundPopupPortuguese").css({
            "opacity": "0.7"
        });
        $("#backgroundPopupPortuguese").fadeIn("slow");
        $("#popupContactPortuguese").fadeIn("slow");
        popupStatus = 1;
    }
}

//loading popup with jQuery magic!
function loadPopupSetYourLocation() {
    //loads popup only if it is disabled

    if (popupStatus == 0) {
        $("#backgroundPopupSetYourLocation").css({
            "opacity": "0.7"
        });
        $("#backgroundPopupSetYourLocation").fadeIn("slow");
        $("#popupSetYourLocation").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopupGood() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopupGood").fadeOut("slow");
        $("#popupContactGood").fadeOut("slow");
        popupStatus = 0;
    }
}

//disabling popup with jQuery magic!
function disablePopupAverage() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopupAverage").fadeOut("slow");
        $("#popupContactAverage").fadeOut("slow");
        popupStatus = 0;
    }
}

//disabling popup with jQuery magic!
function disablePopupPoor() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopupPoor").fadeOut("slow");
        $("#popupContactPoor").fadeOut("slow");
        popupStatus = 0;
    }
}

//disabling popup with jQuery magic!
function disablePopupPolish() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopupPolish").fadeOut("slow");
        $("#popupContactPolish").fadeOut("slow");
        popupStatus = 0;
    }
}

//disabling popup with jQuery magic!
function disablePopupPortuguese() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopupPortuguese").fadeOut("slow");
        $("#popupContactPortuguese").fadeOut("slow");
        popupStatus = 0;
    }
}

//disabling popup with jQuery magic!
function disablePopupSetYourLocation() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopupSetYourLocation").fadeOut("slow");
        $("#popupSetYourLocation").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup 
function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant 
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant 
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode 
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return { X: scrOfX, Y: scrOfY };
}

function getWindowSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE 
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode' 
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible 
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return { X: myWidth, Y: myHeight }
}

//centering popup
function centerPopupGood() {
    //request data for centering
    var windowDim = getWindowSize();
    var popupHeight = $("#popupContactGood").height();
    var popupWidth = $("#popupContactGood").width();
    var scroll = getScrollXY();
    //centering 
    $("#popupContactGood").css({
        "position": "absolute",
        "top": windowDim.Y / 2 - popupHeight / 2 + scroll.Y - 15,
        "left": windowDim.X / 2 - popupWidth / 2 + scroll.X - 15
    });
    //only need force for IE6 

    $("#backgroundPopupGood").css({
        "height": windowDim.Y
    });
}
function centerPopupAverage() {
    //request data for centering
    var windowDim = getWindowSize();
    var popupHeight = $("#popupContactAverage").height();
    var popupWidth = $("#popupContactAverage").width();
    var scroll = getScrollXY();
    //centering 
    $("#popupContactAverage").css({
        "position": "absolute",
        "top": windowDim.Y / 2 - popupHeight / 2 + scroll.Y - 15,
        "left": windowDim.X / 2 - popupWidth / 2 + scroll.X - 15
    });
    //only need force for IE6 

    $("#backgroundPopupAverage").css({
        "height": windowDim.Y
    });
}
function centerPopupPoor() {
    //request data for centering
    var windowDim = getWindowSize();
    var popupHeight = $("#popupContactPoor").height();
    var popupWidth = $("#popupContactPoor").width();
    var scroll = getScrollXY();
    //centering 
    $("#popupContactPoor").css({
        "position": "absolute",
        "top": windowDim.Y / 2 - popupHeight / 2 + scroll.Y - 15,
        "left": windowDim.X / 2 - popupWidth / 2 + scroll.X - 15
    });
    //only need force for IE6 

    $("#backgroundPopupPoor").css({
        "height": windowDim.Y
    });
}

function centerPopupPolish() {
    //request data for centering
    var windowDim = getWindowSize();
    var popupHeight = $("#popupContactPolish").height();
    var popupWidth = $("#popupContactPolish").width();
    var scroll = getScrollXY();
    //centering 
    $("#popupContactPolish").css({
        "position": "absolute",
        "top": windowDim.Y / 2 - popupHeight / 2 + scroll.Y - 15,
        "left": windowDim.X / 2 - popupWidth / 2 + scroll.X - 15
    });
    //only need force for IE6 

    $("#backgroundPopupPolish").css({
        "height": windowDim.Y
    });
}

function centerPopupPortuguese() {
    //request data for centering
    var windowDim = getWindowSize();
    var popupHeight = $("#popupContactPortuguese").height();
    var popupWidth = $("#popupContactPortuguese").width();
    var scroll = getScrollXY();
    //centering
    $("#popupContactPortuguese").css({
        "position": "absolute",
        "top": windowDim.Y / 2 - popupHeight / 2 + scroll.Y - 15,
        "left": windowDim.X / 2 - popupWidth / 2 + scroll.X - 15
    });
    //only need force for IE6

    $("#backgroundPopupPortuguese").css({
        "height": windowDim.Y
    });
}

//centering popup
function centerPopupSetYourLocation() {
    //request data for centering
    var windowDim = getWindowSize();
    var popupHeight = $("#popupSetYourLocation").height();
    var popupWidth = $("#popupSetYourLocation").width();
    var scroll = getScrollXY();
    //centering 
    $("#popupSetYourLocation").css({
        "position": "absolute",
        "top": windowDim.Y / 2 - popupHeight / 2 + scroll.Y - 15,
        "left": windowDim.X / 2 - popupWidth / 2 + scroll.X - 15
    });
    //only need force for IE6 

    $("#backgroundPopupSetYourLocation").css({
        "height": windowDim.Y
    });
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {

    //LOADING POPUP
    //Click the button event!
    $("#btnGood").click(function() {
        
        //centering with css
        centerPopupGood();
        //load popup
        loadPopupGood();
    });

    $("#btnAverage").click(function() {
        //centering with css
        centerPopupAverage();
        //load popup
        loadPopupAverage();
    });

    $("#btnPoor").click(function() {
        //centering with css
        centerPopupPoor();
        //load popup
        loadPopupPoor();
    });

    $("#btnPolish").click(function() {
        //centering with css
        centerPopupPolish();
        //load popup
        loadPopupPolish();
    });

    $("#btnPortuguese").click(function() {
        //centering with css
        centerPopupPortuguese();
        //load popup
        loadPopupPortuguese();
    });

	$("#btnSetYourLocation").click(function() {
        
        //centering with css
        centerPopupSetYourLocation();
        //load popup
        loadPopupSetYourLocation();
    });
    
    //CLOSING POPUP
    //Click the x event!
    $("#popupContactCloseGood").click(function() {
        disablePopupGood();
    });
    $("#popupContactCloseAverage").click(function() {
        disablePopupAverage();
    });
    $("#popupContactClosePoor").click(function() {
        disablePopupPoor();
    });
    $("#popupContactClosePolish").click(function() {
        disablePopupPolish();
    });
    $("#popupContactClosePortuguese").click(function() {
        disablePopupPortuguese();
    });
    $("#popupSetYourLocationClose").click(function() {
        disablePopupSetYourLocation();
    });


    //Click out event!
    $("#backgroundPopupGood").click(function() {
        disablePopupGood();
    });
    $("#backgroundPopupAverage").click(function() {
        disablePopupAverage();
    });
    $("#backgroundPopupPoor").click(function() {
        disablePopupPoor();
    });
    $("#backgroundPopupPolish").click(function() {
        disablePopupPolish();
    });
    $("#backgroundPopupPortuguese").click(function() {
        disablePopupPortuguese();
    });
    $("#backgroundPopupSetYourLocation").click(function() {
        disablePopupSetYourLocation();
    });

    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

});
