function getPageScrollY() {
  if (window.pageYOffset) {
    return window.pageYOffset;
  } else if (document.body && document.body.scrollTop) {
    return document.body.scrollTop;
  } else if (document.documentElement && document.documentElement.scrollTop) {
    return document.documentElement.scrollTop;
  }
  return 0;
};

function getPageScrollX() {
  if (window.pageXOffset) {
    return window.pageXOffset;
  } else if (document.body && document.body.scrollLeft) {
    return document.body.scrollLeft;
  } else if (document.documentElement && document.documentElement.scrollLeft) {
    return document.documentElement.scrollLeft;
  }
  return 0;
};

function getWindowSize() {
  var iWidth = 0;
  var iHeight = 0;
  if (window.innerWidth) {
    iWidth = window.innerWidth || 0;
    iHeight = window.innerHeight || 0;
  } else if (document.compatMode && document.compatMode == 'CSS1Compat') {
    iWidth = document.documentElement.clientWidth || 0;
    iHeight = document.documentElement.clientHeight || 0;
  } else {
    iWidth = document.body.clientWidth || 0;
    iHeight = document.body.clientHeight || 0;
  }
  return {
    width: iWidth,
    height: iHeight
  };
};

function getElementOffset(oEl) {
  var iLeft = iTop = iWidth = iHeight = 0;
  if (oEl.getBoundingClientRect) {
    var oRect = oEl.getBoundingClientRect();
    iLeft = oRect.left;
    iTop = oRect.top;
    iWidth = oRect.right - iLeft;
    iHeight = oRect.bottom - iTop;
    iLeft += getPageScrollX() - 2;
    iTop += getPageScrollY() - 2;
  } else if (document.getBoxObjectFor) {
    var oRect = document.getBoxObjectFor(oEl);
    iLeft = oRect.x;
    iTop = oRect.y;
    iWidth = oRect.width;
    iHeight = oRect.height;
  } else {
    iWidth = oEl.offsetWidth;
    iHeight = oEl.offsetHeight;
    while (oEl.offsetParent) {
      iLeft += oEl.offsetLeft;
      iTop += oEl.offsetTop;
      oEl = oEl.offsetParent;
    }
  }
  return {
    left: iLeft,
    top: iTop,
    width: iWidth,
    height: iHeight
  };
};

function showOrigImage(sId) {
  var oDiv = document.getElementById('div-' + sId + '-orig');
  oDiv.style.display = '';
  oDiv.style.left = (oDiv.parentNode.offsetWidth + 1) + 'px';
  oDiv.style.top = '0px';
  var iTop = 0;
  var oWinSz = getWindowSize();
  oWinSz.height += getPageScrollY();
  var oOffset = getElementOffset(oDiv);
  iTop -= oOffset.top + oOffset.height - oWinSz.height;
  if (iTop > 0) {
    iTop = 0;
  }
  oDiv.style.top = iTop + 'px';
}

function hideOrigImage(sId) {
  document.getElementById('div-' + sId + '-orig').style.display = 'none';
}

function watchVideo(sHtml) {
  x = 0;
  y = 0;

  if (screen) {
      y = (screen.availHeight - 480)/2;
      x = (screen.availWidth - 640)/2;
  }

  var oWin = window.open('', 'videoWindow',
   'width=300,height=300,screenX='+x+',screenY='+y+',top='+y+',left='+x);
  oWin.document.write('<!DOCTYPE html PUBLIC\
   "-//W3C//DTD XHTML 1.0 Transitional//EN"\
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\
   <html xmlns="http://www.w3.org/1999/xhtml">\
   <head><title>Watch Video</title></head>\
   <body style="margin:0px"><table cellpadding="0" cellspacing="0"><tr><td>' +
   sHtml + '</td></tr></table></body></html>');
  var oDiv = oWin.document.body.getElementsByTagName('table')[0];
  oWin.resizeBy(oDiv.offsetWidth - 300, oDiv.offsetHeight - 300);
}
