/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
var popupStatus = false;

//loading popup with jQuery magic!
function loadPopup()
{
    //loads popup only if it is disabled
    if (!popupStatus) {
        $('#backgroundPopup').css('opacity', '0.7');
        $('#backgroundPopup, #popupContact').fadeIn('slow');

        //Follow the page where scrolled to
        $(window).unbind('scroll').scroll(function() {
            $('#popupContact').stop().animate({
                top: $(document).scrollTop() + ($('#popupContact').height() / 2)
            }, 'slow');
        });

        popupStatus = true;

        /*alert ('booooo!');*/
    }
}

//disabling popup with jQuery magic!

function disablePopup()
{
    //disables popup only if it is enabled
    if (popupStatus) {
        $('#backgroundPopup, #popupContact').fadeOut('slow');
        popupStatus = false;
    }
}

//centering popup
function centerPopup()
{
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();

    //centering
    $('#popupContact').css({
        position: 'absolute',
        top: windowHeight / 2 - popupHeight / 2,
        left: windowWidth / 2 - popupWidth / 2
    });

    $('#backgroundPopup').css('height', $(document).height());
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

    $('#login').click(function() {
        centerPopup();
        loadPopup();
    });

    $('#login3').click(function() {
        centerPopup();
        loadPopup();
    });

     $('#login4').click(function() {
        centerPopup();
        loadPopup();
    });


    $('#popupContactClose').click(function() {
        disablePopup();
    });

    $('#backgroundPopup').click(function() {
        disablePopup();
    });
    
    $(window).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus) {
            disablePopup();
        }
    });

        $('#login2').click(function() {
        centerPopup2();
        loadPopup2();
    });

    $("#popupContactClose2a").click(function(){
        disablePopup2();
    });

    $("#popupContactClose2b").click(function(){
        disablePopup2();
    });

    $('#backgroundPopup2').click(function() {
        disablePopup2();
    });

    $(window).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus) {
            disablePopup2();
        }
    });
});

//loading popup with jQuery magic!
function loadPopup2()
{
    //loads popup only if it is disabled
    if (!popupStatus) {
        $('#backgroundPopup2').css('opacity', '0.7');
        $('#backgroundPopup2, #popupContact2').fadeIn('slow');

        //Follow the page where scrolled to
        $(window).unbind('scroll').scroll(function() {
            $('#popupContact2').stop().animate({
                top: $(document).scrollTop() + ($('#popupContact2').height() / 2)
            }, 'slow');
        });

        popupStatus = true;
    }
}

//disabling popup with jQuery magic!

function disablePopup2()
{
    //disables popup only if it is enabled
    if (popupStatus) {
        $('#backgroundPopup2, #popupContact2').fadeOut('slow');
        popupStatus = false;
    }
}


//centering popup
function centerPopup2()
{
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact2").height();
    var popupWidth = $("#popupContact2").width();

    //centering
    $('#popupContact2').css({
        position: 'absolute',
        top: windowHeight / 2 - popupHeight / 2,
        left: windowWidth / 2 - popupWidth / 2
    });

    $('#backgroundPopup2').css('height', $(document).height());
}

//CONTROLLING EVENTS IN jQuery















