/*
 This little bit of JavaScript provides a popup player for playing a simple video

 width and height are width and height of movie.

 playerUrl - The URL to flowplayer-3.0.7.swf
 movieUrl - The URL to the flv file
 baseUrl - The URL to the directory that holds the graphics and other resources.
*/


function ShowPopupPlayer(width, height, movieUrl, baseUrl)
{

    var playerUrl = baseUrl + "/flowplayer/flowplayer-3.0.7.swf";
    var date = new Date();
    var playerId = "player" + date.getTime();
    var border = 60;
    var textHeight = 40;
    var playerContainerWidth = width + border * 2;
    var playerContainerHeight = height + border * 2;
    var windowHeight =  playerContainerHeight + textHeight;
    var windowWidth = playerContainerWidth;
    var playerContainerTop = (playerContainerHeight - height) / 2;
    var div = document.createElement('div');
    div.style.width = windowWidth + "px";
    div.style.height = windowHeight + "px";
    div.style.position = "absolute";
    div.style.float = "left";
    div.style.backgroundColor = "black";
    div.id = "popupplayerdiv";

   var x = (BrowserWindowWidth() - windowWidth) / 2;
   var y = (BrowserWindowHeight() - windowHeight) / 2;
//   x = (window.outerWidth - windowWidth) / 2;
  // y = (window.outerHeight - windowHeight) / 2;

   div.style.top = y + "px";
   div.style.left = x + "px";

    var page = document.getElementById('wrapper');
    if ( page != null ) {
        page.style.display = "none";
    }

    div.innerHTML = '<div style="z-index:10;width:' + playerContainerWidth + 'px;height:' + playerContainerHeight + 'px;"> ' +
                    '<a href="' + movieUrl + '" style="position:relative;margin-left:auto;margin-right:auto;top:' + playerContainerTop + 'px;display:block;width:' + width + 'px;height:' + height + 'px;" id="' + playerId + '"></a>' +
                    '</div>' +
                    '<div style="float:right"><img style="margin-right:10px;margin-top:10px;" src="' + baseUrl + '/closewindow.jpg" /><a style="padding-right:10px" onclick="Close(\'' + playerId + '\');"><img src="' + baseUrl + '/closeicon.jpg" /></a></div>' +
                    '<div style="width:509px;margin-left:auto; margin-right:auto"><img style="margin-top:2px" src="' + baseUrl + '/copyright.jpg" /></div>' +
                    '<script language="javascript">' +
                    '</script>';

    document.body.appendChild(div);

    PauseMusicStacked();
    try {
        flowplayer(playerId, playerUrl, { plugins: { controls: { autoHide: 'always' } } });
    } catch(e) {
    }
    return null;
}

function LoadFlow()
{
}
function BrowserWindowHeight()
{
    return window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
}
function BrowserWindowWidth()
{
    return window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
}

function Close(playerId)
{
    var player = flowplayer(playerId);
    if ( player ) {
        player.unload();
    }
    document.body.removeChild( document.getElementById('popupplayerdiv'));
    var page = document.getElementById('wrapper');
    if ( page != null ) {
        page.style.display = "block";
    }

    StartMusic();

}
