var lightboxStatus = 0;
function wsLightbox(wsImage,wsTime) {
	this.wsImage = wsImage
	$('#popupMessage').html('<img src='+wsImage+'>');
	wsTime = wsTime * 100;
	setTimeout("loadlightbox()", wsTime);
}

function loadlightbox(wsImage){
    centerlightbox();
    if(lightboxStatus==0){
        $("#backgroundpopup").css({
            "opacity": "0.7"
        });
        $("#backgroundpopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        lightboxStatus = 1;
    }
}

function disablelightbox(){
    if(lightboxStatus==1){
        $("#backgroundpopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        lightboxStatus = 0;
    }
}

function centerlightbox(){
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var lightboxHeight = $("#popupContact").height();
    var lightboxWidth = $("#popupContact").width();

     $("#popupContact").css({
        "position": "fixed",
        "top": (windowHeight - lightboxHeight) / 2,
        "left": (windowWidth -lightboxWidth) / 2
    });

    $("#backgroundpopup").css({
        "height": windowHeight
    });

}

$(document).ready(function(){

    $("#popupContactClose").click(function(){
        disablelightbox();
    });

    $("#backgroundpopup").click(function(){
        disablelightbox();
    });

    $(document).keypress(function(e){
        if(e.keyCode==27 && lightboxStatus==1){
            disablelightbox();
        }
    });

});
