﻿//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!   
function loadPopup(imgButton){
    //loads popup only if it is disabled
    //alert(imgButton.id);
    if (popupStatus == 0) {
        $("#backgroundPopup").css({  
            "opacity": "0.7"
        });

        var imLrg = $("#lrgImg");
        var imgParams = imgButton.id.split('_');

        $("#lrgImg").attr("src", "images/art/" + imgParams[0] + ".jpg");

        if (imgParams.length > 1) {
            centerPopup(imgParams[1]);
        }
        else {
            centerPopup(684);
        }

    }
}

function displayPopup() {
    $("#backgroundPopup").fadeIn("slow");
    $("#popupContact").fadeIn("slow");
    popupStatus = 1;
}

//disabling popup with jQuery magic!  
function disablePopup() {  
//disables popup only if it is enabled   
    if(popupStatus==1){  
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow", function () {
            var imLrg = $("#lrgImg");

            $("#lrgImg").attr("src", "");
        }
);
        popupStatus = 0;
    }
}

//centering popup  
function centerPopup(imgWidth) {   
//request data for centering   
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    

    $("#popupContact").css({
        "position": "absolute",
        "top": 10,
        "left": (windowWidth / 2) - (((imgWidth * 1) + 20) / 2)
    });

        //only need force for IE6   
        $("#backgroundPopup").css({
            "height": windowHeight
        });

    //display the pop up
    displayPopup();
    
}

$(document).ready(function () {

    //LOADING POPUP   
    //Click the button event!  
    $("div.Button").click(function () {
        //load popup  
        loadPopup(this);
    });

    //CLOSING POPUP  
    //Click the x event!   
    $("#popupContactClose").click(function () {
        disablePopup();
    });
    //Click out event!  
    $("#backgroundPopup").click(function () {
        disablePopup();
    });
    //Press Escape event!   
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

}); 
