images=new Array();
image_current=1;
currentImage=false;
currentOpacity=0;

function imageSwitchInit(){
	try{
	  var element=false;
	  var idx=1;
	  while(element=getElement('portret_'+idx)){
      element.zidx=10;
      images.push(element);
      idx++;
	  }
    setTimeout("imageSwitch();",3000);
	}catch(e){
		alert("Error imageSwitchInit:"+e.message);
  }
}

function imageSwitch(){
	try{
	  if(images.length>1){
      var imagefrom=false;
      var imageto  =false;

			imageto=(image_current==images.length-1)?images[0]:images[image_current+1];
			imagefrom=images[image_current];

      setOpacity(imageto,0);
      currentOpacity=0;

      currentImage=imageto;
			imageto.zidx=imagefrom.zidx+1;

      imagefrom.style.zIndex=imageto.zidx-1;
      imageto.style.zIndex=imageto.zidx;

			//alert(imagefrom.style.zIndex+':'+imageto.style.zIndex);

	    image_current=image_current+1;
			if(image_current>=images.length)image_current=0;
      setTimeout("imageSwitch();",5000);
      setTimeout("modifyOpacity();",50);
    }
	}catch(e){
		alert("Error imageSwitch:"+e.message);
  }
}

function modifyOpacity(){
	try{
    currentOpacity=currentOpacity+10;
    setOpacity(currentImage,currentOpacity);
	  if(currentOpacity<100){
			setTimeout("modifyOpacity();",50);
	  }
	}catch(e){
		alert("Error modifyOpacity:"+e.message);
  }
}


addEvent(window,"load",imageSwitchInit);		

