﻿
var popupStatus1 = 0;

//loading popup with jQuery magic!
function loadPopup1() {
    //loads popup only if it is disabled
    if (popupStatus1 == 0) {
        $("#ustreamPopUp").html("<iframe src='http://www.ustream.tv/embed/7743130' style='border: 0px none transparent;' frameborder='0' height='396px' scrolling='no' width='100%'></iframe>");
        $("#backgroundPopup1").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup1").fadeIn("slow");
        $("#popupContact1").fadeIn("slow");
        popupStatus1 = 1;
        window.location.hash = "#BlockID=0";        
    }
}

//disabling popup with jQuery magic!
function disablePopup1() {
    //disables popup only if it is enabled
    if (popupStatus1 == 1) {
        $("#backgroundPopup1").fadeOut("slow");
        $("#popupContact1").fadeOut("slow");
        popupStatus1 = 0;
        $("#ustreamPopUp").html("");
        window.location.hash = "";
    }
}

//centering popup
function centerPopup1() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact1").height();
    var popupWidth = $("#popupContact1").width();
    //centering
    $("#popupContact1").css({
        "position": "absolute",
        "top": windowHeight / 2.1 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //only need force for IE6

    $("#backgroundPopup1").css({
        "height": windowHeight
    });

}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function () {

    //LOADING POPUP
    //Click the button event!
    $("#ustreambutton").click(function () {
        centerPopup1();
        loadPopup1();
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose1").click(function () {
        disablePopup1();
    });
    //Click out event!
    $("#backgroundPopup1").click(function () {
        disablePopup1();
    });
    //Press Escape event!
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popupStatus1 == 1) {
            disablePopup1();
        }
    });

});
