//parameters:
var fullBleedDivName = "livestreamPlayer";
var altFullBleedDivName = '';

var firstFullBleed = true;
var oTop;
var oLeft;
var oWidth;
var oHeight;

var fullBleedBars = false;
var topBarHeight = 0;
var bottomBarHeight = 0;

var windowWidth = 0;
var windowHeight = 0;
var videodims = 16 / 9;

function getWindowDimensions() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
}

function resizeFullBleed() {
  getWindowDimensions();
  windowHeight = windowHeight - topBarHeight - bottomBarHeight;
  var vidDiv = document.getElementById(fullBleedDivName);
  if (fullBleedBars || ((windowWidth/windowHeight) >= videodims))  // screen too wide, so set video width to screen width, or top-bottom bars
  {
    vidDiv.style.width = windowWidth + "px";
    var newheight = windowWidth / videodims;
    vidDiv.style.height = newheight + "px";
    vidDiv.style.top = ( ((newheight - windowHeight) / -2) + topBarHeight) + "px";
    vidDiv.style.left = "0px";
  } else {
    vidDiv.style.height = windowHeight + "px";
    var newwidth = windowHeight * videodims;
    vidDiv.style.width = newwidth + "px";
    vidDiv.style.left = ((newwidth - windowWidth) / -2 ) + "px";
    vidDiv.style.top = topBarHeight + "px";
  }

  if (altFullBleedDivName != '') {
    var altVidDiv = document.getElementById(altFullBleedDivName);
    altVidDiv.style.width = vidDiv.style.width;
    altVidDiv.style.height = vidDiv.style.height;
    altVidDiv.style.top = vidDiv.style.top;
    altVidDiv.style.left = vidDiv.style.left;
  }
}

function startFullBleed() {
  $("body").css("overflow", "hidden");

  var vidDiv = document.getElementById(fullBleedDivName);

  vidDiv.style.margin = "0px 0px 0px 0px";

  if (firstFullBleed) {
    firstFullBleed = false;
    oTop = vidDiv.style.top;
    oLeft = vidDiv.style.left;
    oWidth = vidDiv.style.width;
    oHeight = vidDiv.style.height;
  }

  resizeFullBleed();
  window.onresize=resizeFullBleed;
}

function pauseFullBleed() {
  window.onresize=function(){};
}

function stopFullBleed() {
  window.onresize=function(){};
  var vidDiv = document.getElementById(fullBleedDivName);
  vidDiv.style.top = oTop;
  vidDiv.style.left = oLeft;
  vidDiv.style.width = oWidth;
  vidDiv.style.height = oHeight;
  //$("body").css("overflow", "visible");  //doesnt work on FF... wtf!?!?!??!?!?
}

