var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
    //loads popup only if it is disabled
    if(popupStatus==0){
        $("#backgroud_popup_div_for_all_page_as_hidden").css({
            "opacity": "0.3"
        });
        $("#backgroud_popup_div_for_all_page_as_hidden").fadeIn("slow");
        $("#popupLoginFormHeader").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup(){
    //disables popup only if it is enabled
    if(popupStatus==1){
        $("#backgroud_popup_div_for_all_page_as_hidden").fadeOut("slow");
        $("#popupLoginFormHeader").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup(){
    //request data for centering
    var windowWidth = $("#maintable").width();
    var windowHeight = screen.height;    
    var popupHeight = $("#popupLoginFormHeader").height();
    var popupWidth = $("#popupLoginFormHeader").width();
    //centering
    $("#popupLoginFormHeader").css({
        "position": "absolute",
        "top": (windowHeight - popupHeight) / 2,
        "left": (windowWidth - popupWidth) / 2
    });
    //only need force for IE6

    $("#backgroud_popup_div_for_all_page_as_hidden").css({
        "height": windowHeight
    });
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
    $("#button254136").click(function() {
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
        return false;
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupLoginFormHeaderClose").click(function(){
        disablePopup();
    });
    //Click out event!
    $("#backgroud_popup_div_for_all_page_as_hidden").click(function(){
        disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function(e){
        if(e.keyCode==27 && popupStatus==1){
            disablePopup();
        }
    });
});
