// script slouzi k zobrazeni detailu fotografie v plovoucim boxu
// parametry volani: showDetailPicture(strNazevObrazku, intSirka, intVyska)
// vzdy vraci false
// priklad volani: onClick="return showDetailPicture('sample-detail.jpg', 400, 300);"

var nTop = 0;
var nWindowWidth = 0;
var nWindowHeight = 0;
var nPictureBoxWidth = 0;
var nPictureBoxHeight = 0;
var lFixed = false;

if (navigator.appName == "Microsoft Internet Explorer") {
  window.document.getElementById('divDetailPictureBox').style.position = 'absolute';
  window.document.getElementById('divDetailPictureBox').style.width = 1;
  window.document.getElementById('divDetailPictureBox').style.height = 1;
  lFixed = false;
} else {
  lFixed = true;
}

function getWindowDimension() {
  if( typeof( window.innerWidth ) == 'number' ) {
    nWindowWidth = window.innerWidth;
    nWindowHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    nWindowWidth = document.documentElement.clientWidth;
    nWindowHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    nWindowWidth = document.body.clientWidth;
    nWindowHeight = document.body.clientHeight;
  }
}

function setDetailBoxPosition() {
  getWindowDimension();

  var oDetailPictureBox = window.document.getElementById('divDetailPictureBox');
  var nPositionLeft = (document.body.clientWidth - parseInt(oDetailPictureBox.style.width)) / 2;
  var nPositionTop = nTop + ((nWindowHeight / 2) - (parseInt(oDetailPictureBox.style.height) / 2));

  if (nPositionLeft < 0) {nPositionLeft = 0};  
  if (nPositionTop < 120) {
    nPositionTop = 120;
    if (lFixed) {
      oDetailPictureBox.style.top = '0px';
    }
  }

  if (lFixed && ((parseInt(oDetailPictureBox.style.height) + 140) > nWindowHeight)) {
    oDetailPictureBox.style.position = 'absolute';
  }

  if ((parseInt(oDetailPictureBox.style.height) < nWindowHeight) && (!lFixed)) {
    oDetailPictureBox.style.top = nPositionTop + 'px';
  }
  oDetailPictureBox.style.left = nPositionLeft + 'px';
}

function showDetailPicture(cPicture, nWidth, nHeight) {
  nPictureBoxWidth = nWidth + 40;
  nPictureBoxHeight = nHeight + 40;

  oDetailPictureBox = window.document.getElementById('divDetailPictureBox');
  oDetailPictureBoxHTML = window.document.getElementById('divDetailPictureBoxHTML');

  oDetailPictureBoxHTML.innerHTML = '<img src="' + cPicture + '" width="' + nWidth + '" height="' + nHeight + '" alt="">';
  oDetailPictureBox.style.width = nPictureBoxWidth + 'px';
  oDetailPictureBox.style.height = nPictureBoxHeight + 'px';

  setDetailBoxPosition();
  oDetailPictureBox.style.display = 'block';

  return false;
}

function hideDetailPicture() {
  oDetailPictureBox = window.document.getElementById('divDetailPictureBox');
  oDetailPictureBox.style.display = 'none';
  
  return false;
}

function myOnScroll() {
  nTop = document.documentElement.scrollTop;
  setDetailBoxPosition();
}

window.onscroll = myOnScroll;
