﻿//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#pageMask").css({
            "opacity": "0.7"
        });
        $("#pageMask").fadeIn("slow");
        $("#popupHolder").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#pageMask").fadeOut("slow");
        $("#popupHolder").fadeOut("slow");
        // clear html from div
        $("#popupContent").html("");
        popupStatus = 0;
    }
}

function changeDimensionPopup(arg_width, arg_height) {
    $("#popupContent").height(arg_height);
    $("#popupContent").width(arg_width);
}


//centering popup
function centerPopup() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var divContainerWidth = $("#divContainer").width();
    var popupHeight = $("#popupHolder").height();
    var popupWidth = $("#popupHolder").width();
    //centering
    $("#popupHolder").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": divContainerWidth / 2 - popupWidth / 2
    });

    //only need force for IE6
    $("#pageMask").css({
        "height": windowHeight
    });
}

// resize mask as page is resized
$(window).resize(function() {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    $("#pageMask").css({
        "height": windowHeight,
        "width": windowWidth
    });
});

//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {

    $("#btnZDS_Introduction_Show").click(function() {
        changeDimensionPopup(645, 550);
        centerPopup();  //centering with css
        loadPopup();    	//load popup
        // write iframe into popup content
        $("#popupContent").html("<iframe src='Flash/ZDSIntroductionShowFlash.htm' width='100%' height='100%' scrolling='no' marginheight='0' marginwidth='0' frameborder='0'><p>Your browser does not support iframes.</p></iframe>");
    });

    $("#btnZDS_Client_Show").click(function() {
        changeDimensionPopup(725, 585);
        centerPopup();  //centering with css
        loadPopup();    	//load popup
        // write iframe into popup content
        $("#popupContent").html("<iframe src='Flash/ZDSClientPresentationShowFlash.htm' width='100%' height='100%' scrolling='no' marginheight='0' marginwidth='0' frameborder='0'><p>Your browser does not support iframes.</p></iframe>");
    });

    $("#btnZDS_DataCollection_Show").click(function() {
        changeDimensionPopup(725, 620);
        centerPopup();  //centering with css
        loadPopup();    	//load popup
        // write iframe into popup content
        $("#popupContent").html("<iframe src='Flash/ZDSDataCollectionShowFlash.htm' width='100%' height='100%' scrolling='no' marginheight='0' marginwidth='0' frameborder='0'><p>Your browser does not support iframes.</p></iframe>");
    });

    $("#WebinarSummaryOutput").click(function() {
        changeDimensionPopup(880, 494);
        centerPopup();  //centering with css
        loadPopup();    	//load popup
        // write iframe into popup content
        $("#popupContent").html("<iframe src='Includes/ZDSWebinarListShow.htm' width='880' height='454' scrolling='no' marginheight='0' marginwidth='0' frameborder='0'><p>Your browser does not support iframes.</p></iframe>");
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupClose").click(function() {
        disablePopup();
    });
    //Click out event!
    $("#pageMask").click(function() {
        disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

});



