var _floorVideoWindow;
var _floorVideoWindowOpener;

function FloorVideoWindow(url)
{
  if( url != null )
  {
    this.show(url);
  }
}

function FloorVideoWindow_show(url)
{
  var width = 870;
  var height = 650;

  if( url.indexOf( "vmgrView" ) > 0 )
  {
    height += 15;
  }
  else if( url.indexOf( "vmgrEmail" ) > 0 )
  {
    height += 15;
  }
  else if( url.indexOf( "vmgrClip" ) > 0 )
  {
    height += 75;
  }
  else if( url.indexOf( "vmgrEdit" ) > 0 )
  {
    height += 240;
  }

  var maxHeight = parseInt(screen.height,10);
  if(!maxHeight)
  {
    maxHeight = 760;
  }

  maxHeight -= 30;

  // max height: allot room for window title, border, etc.)
  if(height > maxHeight)
  {
    height = maxHeight;
  }

   _floorVideoWindow = window.open(url, "cqFloorVideoWindow",'resizable,scrollbars,width=' + width + ',height=' + height);
   _floorVideoWindow.focus();
   _floorVideoWindowOpener = _floorVideoWindow.opener;

   if( _floorVideoWindowOpener && _floorVideoWindowOpener.onVideoWindowOpened )
   {
     _floorVideoWindowOpener.onVideoWindowOpened();
   }

   setTimeout( "FloorVideoWindow_checkIfStillOpen()", 1000 );
}

function FloorVideoWindow_showImageWindow(imageUrl,width,height)
{
  if(!width)
  {
    width = 340;
  }

  if(!height)
  {
    height = 260;
  }

/*
  var html = '<html><head><title>CQ Floor Video - Image</title></head><body style="background-color:#313131;margin:0;padding:0;">';
  html += '<img src="' + imageUrl + '" style="margin:5px;" onclick="javascript:window.close();" />';
  html += '</body></html>';
*/

   _thumbnailWindow = window.open(imageUrl, "cqFloorVideoThumbnailWindow",'width=' + width + ',height=' + height);
   _thumbnailWindow.focus();
}

function FloorVideoWindow_checkIfStillOpen()
{
  if( _floorVideoWindow == null || _floorVideoWindow.closed || !_floorVideoWindow.open )
  {
    if( _floorVideoWindow && _floorVideoWindowOpener && _floorVideoWindowOpener.onVideoWindowClosed )
    {
      _floorVideoWindowOpener.onVideoWindowClosed();
    }

    _floorVideoWindow = null;
  }
  else
  {
    setTimeout( "FloorVideoWindow_checkIfStillOpen()", 1000 );
  }
}

FloorVideoWindow.prototype.show = FloorVideoWindow_show;
FloorVideoWindow.prototype.showImageWindow = FloorVideoWindow_showImageWindow;
