var Showed = false;
var TimeOut = 0 ;
var timerID = null;
var PicWidth = 0;
var PicHeight = 0;
var xStep = 0;
var yStep = 0;
var MaxStep = 5;
var Step = 0;
var PrevName = '';

function initDIV(fName, fWidth, fHeight)
 {
 if (Showed) 
  {
  PopupDiv.parentNode.removeChild(PopupDiv);
  if (PrevName == fName)
   {
   Showed=false;
   return;
   }
  }
 
 PrevName = fName;
 PicWidth = fWidth;
 PicHeight = fHeight;
 xStep=Math.ceil(PicWidth/MaxStep);
 yStep=Math.ceil(PicHeight/MaxStep);
 Step = 1;
 
 PopupDiv = document.createElement('DIV');
 PopupDiv.id = 'PopupDiv';
 PopupDiv.style.zIndex = 1000;
 document.body.appendChild(PopupDiv);

 PopupDiv.innerHTML='<img OnClick="PopupDiv.parentNode.removeChild(PopupDiv); Showed=false;" id="ImgDiv" src="'+fName+'" width="'+xStep+'" height="'+yStep+'" Title="Закрыть"></div>';
  
 Left = (document.body.clientWidth-xStep)/2;
 Top = (document.body.clientHeight-yStep)/2+document.body.scrollTop;
// alert(document.body.scrollTop);
// Top = (screen.height-yStep)/2;
// alert(screen.height);
 
 PopupDiv.style.left = Left + 'px';
 PopupDiv.style.top = Top + 'px';
 Showed = true;

 timerID = setTimeout("Raise()", TimeOut);
 }
 
function Raise()
 {
 Step++;
 if (Step > MaxStep)
  {
  clearTimeout(timerID); 
  DivImg.src = DivImg.src;
  return;
  }
  
 NewWidth = Step*xStep;
 if (NewWidth > PicWidth)
  {
//  xSlide = (NewWidth-PicWidth)/2; 
  xSlide = (xStep-NewWidth+PicWidth)/2; 
  NewWidth = PicWidth;
  } 
 else xSlide = xStep/2;
  
 NewHeight = Step*yStep;
 if (NewHeight > PicHeight)
  {
//  ySlide = yStep/2-(NewHeight-PicHeight)/2;
  ySlide = (yStep-NewHeight+PicHeight)/2; 
  NewHeight = PicHeight;
  } 
 else ySlide = yStep/2;
 
  
 PopupDiv = document.getElementById('PopupDiv');
 if (PopupDiv.offsetLeft - xSlide > 0) PopupDiv.style.left = PopupDiv.offsetLeft - xSlide;
 if (PopupDiv.offsetTop - ySlide > 0) PopupDiv.style.top = PopupDiv.offsetTop - ySlide;
 
 DivImg = document.getElementById('ImgDiv');
 DivImg.style.width = NewWidth;
 DivImg.style.height = NewHeight;
 
 timerID = setTimeout("Raise()", TimeOut);
 }
  

