var zoomed = false;
var origPlayerHeight = origPlayerWidth = 0;
var playerId = 'VBOXplayer';

var makeFullscreenBind;

function togglePlayerZoom() {
    zoomed ? unzoomPlayer() : zoomPlayer();
}

function zoomPlayer() {
    if (zoomed) {
		return;
    } else {
        zoomed = true;
		origPlayerHeight = $j('#'+ playerId).height();
		origPlayerWidth = $j('#'+ playerId).width();
    }
	
    makeFullscreen();
	
	$j(window).bind('resize', makeFullscreen);
	$j(window).bind('scroll', makeFullscreen);
}

function makeFullscreen() {
    scroll(0,0);

    var windowDimensions = getWindowDimensions();
	
	$j('#bdall').css({
		overflow: 'hidden',
		height: windowDimensions.height,
		width: windowDimensions.width
	})
	
	$j('html').css('overflow', 'hidden');
	
	windowDimensions = getWindowDimensions();

    var video_player = document.getElementById('VBOXplayer');
	var absPos = $j('#VBOXplayer').offset();
	var curPos = $j('#VBOXplayer').position();
	
	$j('#VBOXplayer').css({
		position: 'absolute',
		'z-index': 9999,
		top: '-'+ (absPos[1] - curPos[1]) +'px',
		left: '-'+ (absPos[0] - curPos[0]) +'px',
		width: windowDimensions.width,
		height: windowDimensions.height
	})
}


function unzoomPlayer() {
    if (!zoomed) {
        return;
    } else {
        zoomed = false;
    }

    var video_player = document.getElementById('VBOXplayer');
	
	$j(window).unbind('resize', makeFullscreen);
	$j(window).unbind('scroll', makeFullscreen);
	
	$j('#bdall').css({
		overflow: 'visible',
		height: 0,
		width: 0
	})
	
	$j('html').css('overflow', 'auto');
	
	$j('#VBOXplayer').css({
		position: 'relative',
		top: 0,
		left: 0,
		width: origPlayerWidth,
		height: origPlayerHeight
	})
}


function getWindowDimensions()
{
    var dimensions;

    if(window.innerWidth != null)
    {
        dimensions =
        {
            width: window.innerWidth,
            height: window.innerHeight
        };
    }
    else if (document.documentElement && document.documentElement.clientWidth)
    {
        dimensions =
        {
            width: document.documentElement.clientWidth,
            height: document.documentElement.clientHeight
        };
    }
    else if (document.body != null)
    {
        dimensions =
        {
            width: document.body.clientWidth,
            height: document.body.clientHeight
        };
    }

    return dimensions;
}
