var stopped=-1, rotate_timer, hT, sT,interval=4000; // change this value to change the speed, ie: 2000 = 2 seconds between slides

function SmoothShow(objId, x)   
{
   var obj = document.getElementById(objId);
   op = (obj.style.opacity)?parseFloat(obj.style.opacity):parseInt(obj.style.filter)/100; 
	     
   if(op < x)  
   { 
      clearTimeout(hT);
      op += 0.05; 
      obj.style.opacity = op; 
      sT=setTimeout("SmoothShow(\'"+objId+"\',"+x+")",50); 
   } 
}

function SmoothHide(objId, x)   
{ 
   var obj = document.getElementById(objId);
   op = (obj.style.opacity)?parseFloat(obj.style.opacity):parseInt(obj.style.filter)/100; 
	     
   if(op > x)  
   { 
      clearTimeout(sT);
      op -= 0.05; 
      obj.style.opacity = op; 
      hT=setTimeout("SmoothHide(\'"+objId+"\',"+x+")",50);
   } 
}

function stopStartRotate()
{
    if (stopped==1)
    {
        rotate(0);
        document.getElementById("d").innerHTML="Остановить";
        stopped=-1;
    }
    else if (stopped==-1)
    {
        clearTimeout(rotate_timer);
        document.getElementById("d").innerHTML="Продолжить";
        clearTimeout(sT);
        clearTimeout(hT);
        document.getElementById("p").style.opacity = 1;
        stopped=1;
    }
}

function rotate(state)
{
  if (document.getElementById("p")==null)
     return;
  if(state==1)
  {
      next=(Math.floor(Math.random()* (51))+1);
      if (document.getElementById("p").src=="/style/slides/"+next+".jpg")
        next=abs(next-50)+1;
      document.getElementById("p").src="/style/slides/"+next+".jpg";
      document.getElementById("p").style.opacity = 0.3;
      SmoothShow("p", 1);
      rotate_timer=setTimeout("rotate(0)",interval);
  }
  else
  {
      SmoothHide("p", 0.1);
      rotate_timer=setTimeout("rotate(1)",500);
  }
}
function newWindow (imageLink) 
{   
    var newImg = new Image(); 
    newImg.src = imageLink.src.replace("/min",""); 
    curHeight = newImg.height; 
    curWidth = newImg.width; 
    ScrWindow=window.open("","","toolbar=no,location=no,lefta=0px,topa=0px,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width="+curWidth+"px,height="+curHeight+"px"); 
    if (ScrWindow != null && ScrWindow.opener == null) ScrWindow.opener=window; 
    ScrWindow.document.open(); 
    ScrWindow.document.writeln ("<html><head><title>Изображение</title></head><body><img width="+curWidth+" src=\""+newImg.src+"\"></body></html>"); 
    ScrWindow.document.close();
}