﻿var VideoURL = "DISlowMotionBack.flv";

function isIE()
{
    return navigator.appName.indexOf("Microsoft") != -1;
}

function getFlashMovie(movieName)
{
    return (isIE()) ? window[movieName] : document[movieName];
}

function checkVideoPlayerHidden()
{
    if (window.event.propertyName == "style.display")
    {
        if (document.getElementById(window.event.srcElement.id).style.display == "none")
        {
            var ClaussFlashContent = getFlashMovie("videolightboxflashcontent");
            if (ClaussFlashContent != null)
            {
                try
                {
                    ClaussFlashContent.stopMovie();
                }
                catch(err)
                {
                }
            }
        }
    }
}

function openVideoPlayer()
{
    var VideoLightbox = document.getElementById("VideoLightbox");
    if (VideoLightbox != null)
    {        
        var windowWidth;
        var windowHeight;
        var clientWidth;
        var clientHeight;
        var scrollTop;
        var scrollLeft;
       
            if (isIE())
            {
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
                clientWidth = document.body.clientWidth;
                clientHeight = document.body.clientHeight;
                scrollTop = document.body.parentElement.scrollTop;
                scrollLeft = document.body.parentElement.scrollLeft;
            }
            else
            {
                windowWidth = window.innerWidth;
                windowHeight = window.innerHeight;
                clientWidth = document.width;
                clientHeight = document.height;
                scrollTop = window.pageYOffset;
                scrollLeft = window.pageXOffset;
            }
                
            VideoLightbox.style.left = (scrollLeft + ((windowWidth/2) - 375)) + "px";
            VideoLightbox.style.top = (scrollTop + ((windowHeight/2) - 365)) + "px";
        
        var Back = document.getElementById("Back");
        if (Back != null)
        {
            Back.style.width = clientWidth + "px";
            Back.style.height = clientHeight + "px";
            Back.style.top = -115 + "px";
            Back.style.left = 0 + "px";
            Back.style.display = "inline";
        }
    }
}

function closeVideoPlayer()
{
    var VideoLightbox = document.getElementById("VideoLightbox");
    if (VideoLightbox != null)
    {
        VideoLightbox.style.left = "-5000px";
        
        var Back = document.getElementById("Back");
        if (Back != null)
        {
            Back.style.display = "none";
        }
    }
}

function isVideoURLSynced(videoURL)
{
    alert(videoURL);
    return (VideoURL == videoURL);
}

function getVideoURL()
{
    return VideoURL;
}

function setVideoURL(videoURL)
{
    VideoURL = videoURL;
        
    var ClaussFlashContent = getFlashMovie("videolightboxflashcontent");
    if (ClaussFlashContent != null)
    {
        try
        {
            ClaussFlashContent.setVideoURL(VideoURL);
        }
        catch(err)
        {
        }
    }
}

function stopVideoPlayer()
{
    var ClaussFlashContent = getFlashMovie("videolightboxflashcontent");
    if (ClaussFlashContent != null)
    {
        try
        {
            ClaussFlashContent.stopMovie();
        }
        catch(err)
        {
        }
    }
}

function sleep(miliseconds)
{
    var sleeping = true;
    var now = new Date().getTime();
    while (sleeping)
    {
        alarm = new Date().getTime();
        if (alarm - now > miliseconds)
        {
            sleeping = false;
        }
    }
}

function resetVideoPosition()
{
    var VideoLightbox = document.getElementById("VideoLightbox");
    if (VideoLightbox != null)
    {
        if (VideoLightbox.style.display != "none" &&
            VideoLightbox.style.left != "-5000px")
        {
            var windowWidth;
            var windowHeight;
            var clientWidth;
            var clientHeight;
            var scrollTop;
            var scrollLeft;
            
            if (isIE())
            {
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
                clientWidth = document.body.clientWidth;
                clientHeight = document.body.clientHeight;
                scrollTop = document.body.parentElement.scrollTop;
                scrollLeft = document.body.parentElement.scrollLeft;
            }
            else
            {
                windowWidth = window.innerWidth;
                windowHeight = window.innerHeight;
                clientWidth = document.width;
                clientHeight = document.height;
                scrollTop = window.pageYOffset;
                scrollLeft = window.pageXOffset;
            }
                    
                VideoLightbox.style.left = (scrollLeft + ((windowWidth/2) - 375)) + "px";
                VideoLightbox.style.top = (scrollTop + ((windowHeight/2) - 365)) + "px";
            
            var Back = document.getElementById("Back");
            if (Back != null)
            {
                Back.style.width = clientWidth + "px";
                Back.style.height = clientHeight + "px";
                Back.style.top = -115 + "px";
                Back.style.left = 0 + "px";
                Back.style.display = "inline";
            }
        }
    }
}

window.onscroll = resetVideoPosition;
window.onresize = resetVideoPosition;