function GetWindowInnerWidth()
{
  Width = 630;
  if (document.body && document.body.offsetWidth) Width = document.body.offsetWidth;
  if (document.compatMode == "CSS1Compat" &&
    document.documentElement &&
    document.documentElement.offsetWidth) Width = document.documentElement.offsetWidth;
  if (window.innerWidth) Width = window.innerWidth;
  return Width;
}

function GetWindowInnerHeight()
{
  Height = 630;
  if (document.body && document.body.offsetHeight) Height = document.body.offsetHeight;
  if (document.compatMode == "CSS1Compat" &&
    document.documentElement &&
    document.documentElement.offsetHeight) Height = document.documentElement.offsetHeight;
  if (window.innerHeight) Height = window.innerHeight;
  return Height;
}

function GetBrowserScrollY()
{
  var ScrollY = 0;
  if (typeof(window.pageYOffset) == 'number')                              ScrollY = window.pageYOffset;
  else if (document.body && document.body.scrollTop)                       ScrollY = document.body.scrollTop;
  else if (document.documentElement && document.documentElement.scrollTop) ScrollY = document.documentElement.scrollTop;
  return ScrollY;
}

function GetYouTubeURL(MovieCode)
{
//  return "http://www.youtube.com/embed/http://www.youtube.com/v/"+MovieCode+"?autoplay=1&rel=0&showinfo=0&autohide=1&color=white&modestbranding=1&theme=light";
  return "http://www.youtube.com/embed/"+MovieCode+"?autoplay=1&rel=0&showinfo=0&autohide=1&color=white&modestbranding=1&theme=light";
}

function StartYouTubePlayer(MovieCode)
{
  var YouTubeURL = GetYouTubeURL(MovieCode);
  // create blackout and append to page
  var Blackout          = document.createElement("div");
  Blackout.id           = "youtubeplayer_blackout";
  document.body.appendChild(Blackout);
  // create background image and append to page
  var Background        = document.createElement("div");
  Background.id         = "youtubeplayer_background";
  Background.style.top  = parseInt(GetBrowserScrollY()+0.4*(GetWindowInnerHeight()-510))+"px";
  Background.style.left = parseInt(0.5*(GetWindowInnerWidth()-860))+"px";
  document.body.appendChild(Background);
  // create an ifram for the player
  var Frame             = document.createElement("iframe");
  Frame.id              = "youtubeplayer_frame";
  Frame.width           = 800;
  Frame.height          = 450;
  Frame.setAttribute("frameborder","0");
  Frame.src             = YouTubeURL;
  Background.appendChild(Frame);
  // create stop button and appent to blackout
  var ButtonLink        = document.createElement("a");
  ButtonLink.id         = "youtubeplayer_button";
  ButtonLink.onclick    = function() { StopYouTubePlayer(); };
  Background.appendChild(ButtonLink);
}

// restore page to normal
function StopYouTubePlayer()
{
 // get all elements
 var Blackout   = document.getElementById("youtubeplayer_blackout")
 var Background = document.getElementById("youtubeplayer_background")
 var ButtonLink = document.getElementById("youtubeplayer_button")
 // remove everything in reverse order
 Background.removeChild(ButtonLink);
 document.body.removeChild(Background);
 document.body.removeChild(Blackout);
}

