﻿var popupStatus = 0;

function loadPopup() 
{
    if (popupStatus == 0) 
        $("#corperateVideoBackground").show();
    popupStatus = 1;
}

function disablePopup() 
{
    if (popupStatus == 1) 
    {
        $("#corperateVideoBackground").hide();
        $('#iframeYouTube').attr('src', function (i, val) { return val; });
    }
    popupStatus = 0;
}

function centerPopup() 
{
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#corperateVideoPopup").height();
    var popupWidth = $("#corperateVideoPopup").width();

    $("#corperateVideoPopup").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
}

$(document).ready(function () {
    $('.slideshow').cycle({
        fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });

    // Reassign the non-javascript link.
    $('#videolink').attr('href', 'javascript:');
    $('#videolink').attr('target', '');
 
    $("#buttonvid").click(function () {
        centerPopup();
        loadPopup();
    });

    //Click the x event!
    $("#corperateVideoClose").click(function () {
        disablePopup();
    });

    //Click out event!
    $("#corperateVideoBackground").click(function () {
        disablePopup();
    });

    //Press Escape event!
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
});
