﻿var vpopupStatus = 0;  //0 means disabled; 1 means enabled;


//centering popup 
function vgetScrollXY() {
    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 vgetWindowSize() {
    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 }
}

function vshowPopup(imgHeight, imgWidth) {
    //request data for centering
    var popupHeight = $("#vpopupBox").css({ "height": imgHeight + (20) }).height();
    var popupWidth = $("#vpopupBox").css({ "width": imgWidth + (20) }).width();
    var windowDim = vgetWindowSize();
    var scroll = vgetScrollXY();
    var scrollbarWidth = 0;

    //centering
    /*
    alert(" popupWidth " + popupWidth + "  ,  windowDim.X " + windowDim.X + "  ,  scroll.X " + scroll.X
    + " , popupHeight " + popupHeight + "  ,  windowDim.Y " + windowDim.Y + "  ,  scroll.Y " + scroll.Y 
    );*/
    $("#vpopupBox").css({ "position": "absolute", "top": ((windowDim.Y - popupHeight) / 2) + scroll.Y, "left": (($("#container").width() - popupWidth) / 2) + scroll.X - scrollbarWidth });
    $("#vbackgroundPopup").css({ "height": windowDim.Y });  //only need force for IE6
    $("#vboxImg").css({ "position": "absolute", "top": popupHeight / 2 - imgHeight / 2, "left": popupWidth / 2 - imgWidth / 2 });

    if (vpopupStatus == 0) {
        $("#vbackgroundPopup").css({ "opacity": "0.6" });
        $("#vbackgroundPopup").fadeIn("slow");
        $("#vpopupBox").fadeIn("slow");
        vpopupStatus = 1;
    }
}

function vdisablePopup() {
    if (vpopupStatus == 1) {
        $("#vbackgroundPopup").fadeOut("slow");
        $("#vpopupBox").fadeOut("slow");
        vpopupStatus = 0;
        $("#csSWF").remove().appendTo("#vboxImg");
    }
}

