
function getWindowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return myHeight;
}

function showPreview(className, id, type, refPrefix)
{
  var loadingDiv = getObj('previewLoadingDiv');
  var loadingImg = getObj('previewLoadingImg');
  var previewDiv = getObj('previewDiv');

  if ( refPrefix )
    G_clickedImgPos = findPos(getObj(refPrefix + id));
  else
    G_clickedImgPos = false;

  if ( loadingImg )
  {
    previewDiv.style.visibility = 'hidden'  
    loadingDiv.style.width  = loadingImg.width + 'px';
    loadingDiv.style.height = loadingImg.height + 'px';
    loadingDiv.style.marginLeft = (Math.round(loadingImg.width / -2)) + 'px';
  }
  else
  {
    loadingDiv.style.marginLeft = (Math.round(parseInt(loadingDiv.style.width) / -2)) + 'px';
    var movie = getFlashMovieObject('previewMovie');
    if ( movie )
    {
      movie.StopPlay();
    }
  }
  if ( G_clickedImgPos )
    loadingDiv.style.top = G_clickedImgPos[1] + 'px';
  else
    loadingDiv.style.top = getScrollY() + 200 + "px";

  previewDiv.innerHTML = '<img id="previewImg" src="cmd.php?cmd=img&class=' + className + '&id=' + id + '&type=' + type + '" alt="" />';
  loadingDiv.style.visibility = 'visible';
  window.setTimeout("waitForImage()", 200);
}

function waitForImage()
{
  if ( imageIsLoaded(getObj('previewImg')) )
  {
    getObj('previewLoadingDiv').style.visibility = 'hidden';
    var previewDiv = getObj('previewDiv');
    var previewImg = getObj('previewImg');
    previewDiv.style.width  = previewImg.width + 'px';
    previewDiv.style.height = previewImg.height + 'px';
    previewDiv.style.marginLeft = (Math.round(previewImg.width / -2)) + 'px';
    if ( G_clickedImgPos )
      previewDiv.style.top = G_clickedImgPos[1] + 'px';
    else
      previewDiv.style.top = getScrollY() + (Math.round((getWindowHeight() - previewImg.height) /  2)) + "px";
    previewDiv.style.visibility = 'visible';

    if ( typeof G_DisableFade != 'undefined' && G_DisableFade )
    {
      getObj('previewDiv').style.visibility = 'visible';
      return;
     }
    else
      fadeIn('previewDiv', 0, 10, 10);
  }
  else
    window.setTimeout("waitForImage()", 50);
}

function hidePreview()
{
  if ( typeof G_DisableFade != 'undefined' && G_DisableFade )
  {
    getObj('previewDiv').style.visibility = 'hidden';
  }
  else
    fadeOut('previewDiv', 100, 10, 10, "getObj('previewDiv').style.visibility = 'hidden';");

}


