var videoOldOnload = window.onload;

window.onload = function()
{
    if (typeof videoOldOnload == 'function')
    {
         videoOldOnload();
    }

    window.videoInstance = new video();
    videoInstance.init();
}

var video = function ()
{

}

video.prototype.init = function()
{
    if (this.isPlayerPopup())
    {
        this.resizePlayerPopup();
    }
    else
    {
        this.initBigPlayerLink();
    }
}

video.prototype.initBigPlayerLink = function()
{
    var link = document.getElementById('bigPlayerLink');
    if (!link)
    {
        return;
    }

    var script = this;
    link.onclick = function()
    {
        return !script.openBigPlayer( this );
    }

}


video.prototype.openBigPlayer = function( link )
{
    var popupLink = link.href.concat('&popup=1');

    var winName = 'video_player_popup';
	var W = 800;
	var H = 600;

	var left = 0;
	var top  = 0;

   	var popupPlayerWin = window.open(popupLink, winName, "scrollbars=0,resizable=1,width=" + W + ",height=" + H + " , top=" + top + ", left=" + left);

    return true;
}

video.prototype.isPlayerPopup = function()
{
    var box = document.getElementById('popupPlayerBox');
    if (box)
    {
        return true;
    }
    return false;
}

video.prototype.resizePlayerPopup = function()
{
    var initW = 600;
    var initH = 400;

    var contentWidth = 800;
    var contentHeight = 640;

    window.resizeTo(initW,initH);
    var size = this.getPopupInnerSize();

    var xToAdd = initW - size[0];
    var yToAdd = initH - size[1];

    var newWidth = contentWidth + xToAdd;
    var newHeight = contentHeight + yToAdd;

    window.resizeTo(newWidth, newHeight);
    var left = Math.round((screen.width-newWidth)/2);
    var top = Math.round((screen.height-newHeight)/2);
    if (top < 0)
    {
        top = 0;
    }
    if (left < 0)
    {
        left = 0;
    }
    window.moveTo(left, top);

}

video.prototype.getPopupInnerSize = function()
{
    var x,y;
    if (window.innerHeight) // all except Explorer
     {
       x = window.innerWidth;
       y = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {  // Explorer 6 Strict Mode
       x = document.documentElement.clientWidth;
       y = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
       x = document.body.clientWidth;
       y = document.body.clientHeight;
    }
    var size = new Array(x, y);

    return size;
}

