// JavaScript Document
var i;
var xxx;
var opacity;
var cross;
var y;
var s;
var period;
var width;
var running;
var slide_img = new Array();

function jcont() {
		   j=i-1;
		   if (j < 0) {j=(carray-1)}
		   if (y==2) {slide1.src = slide_img[j].src;}
		   if (y==1) {slide2.src = slide_img[j].src;}


}
function icont() {
		   i++;
   		   if (i >= carray) {i=0;}
		   if (i < 0) {i=(carray-1)}

}


function movercont() {
	         if(countmover<=0) {countmover = countmover + width;}
	   	     if(countmover>width) {countmover = countmover - width;}
	         
			 if ((position-countmover)>(width/2)) {mover = -((width-position+countmover)/(cross/2))}
      	     else if ((countmover-position)>(width/2)) {mover = ((width-countmover+position)/(cross/2))}
	         else {mover = ((position-countmover)/(cross/2));}
	       //if ((mover>0) && (mover<0.5)) {mover=1}
	       //if ((mover<0) && (mover>-0.5)) {mover=-1}
}
function rolling() {
       position = parseInt(wwarray[j]) - startroll;
       if (position<0) {position=position+width}
   	   countmover = countmover + mover;
	   cmover = Math.round(-countmover);
	   id1.style.left = parseInt(cmover) + 'px';
	   id2.style.left = parseInt(cmover+width) + 'px';
}
function cslide() {
	   if (y==2) {slide1.src = slide_img[i].src;}
	   else {slide2.src = slide_img[i].src;}

}
function crossdiss() {
   if (document.all) {
      if (opacity<100) {
   	  opacity=opacity + Math.ceil(100/cross);
         if (y==1) {
            slide2.style.filter='alpha(opacity='+opacity+')';
	        slide1.style.filter='alpha(opacity='+(100-opacity)+')'; 			  
		 }
         else {
            slide1.style.filter='alpha(opacity='+opacity+')';
	        slide2.style.filter='alpha(opacity='+(100-opacity)+')'; 
		 }
	  }
   }
   else {  	
      if (opacity<1) {
      opacity=opacity + (Math.ceil(100/cross)/100);
         if (y==1) {
	        slide2.style.opacity=opacity;
	        slide1.style.opacity=(1-opacity);
         }
         else {
	        slide1.style.opacity=opacity;
	        slide2.style.opacity=(1-opacity);
	     }
      }
   }
}
function slide_init() {
	i = 1;
	j = 0;
	xxx = 0;
	y = 1;
	s='start';
	opacity = 0;
	slide1 = document.getElementById('imgslide1');
	slide2 = document.getElementById('imgslide2');
	linkimg = document.getElementById('ingrandisce');
	document.getElementById('nojs').style.visibility='hidden';
	running = true;
	       if (document.all) {
              slide2.style.filter='alpha(opacity='+opacity+')';
	          slide1.style.filter='alpha(opacity='+(100-opacity)+')'; 			  
		   }
           else {
	          slide2.style.opacity=opacity;
	          slide1.style.opacity=(1-opacity);
		   }
	slide2.style.visibility='visible'; 
   	
	for(x=0; x<carray; x++) {

	slide_img[x] = new Image();
	slide_img[x].src = fslide + srcarray[x];	}
	//rollingthumb
    countmover = - wphoto;
	
    position = parseInt(wwarray[j]) - startroll;
	id1 = document.getElementById('photoroll');
 	id2 = document.getElementById('photoroll2');
	id1.style.left = startroll +'px';
	id2.style.left = width + startroll + 'px';
	//fine rollingthumb
	
	status();
}
function status() {
slide2.style.top = (hslide + 4 - slide2.offsetHeight)/2 + 'px';
slide1.style.top = (hslide + 4 - slide1.offsetHeight)/2 + 'px';
slide2.style.left = (wphoto + 4 - slide2.offsetWidth)/2 + 'px';
slide1.style.left = (wphoto + 4 - slide1.offsetWidth)/2 + 'px';

     switch(s) {
	    case 'start':
		{
		   mover = ((position-countmover)/cross);
	       if (Math.ceil(countmover) == position) {s='slide'}
   		   jcont();
		   slide();
		   break;
		}
		case 'slide':
		{
   		   jcont();
		   movercont();
		   slide();
		   break;
		}
		case 'show':
		{
		   j=i;
		   movercont();
		   slide();
		   break;
		}
		case 'showall':
		{
		   j=i;
		   movercont();
		   slide()
		   break;
		}
		case 'stop':
		{
		   movercont();
		   slide();
		   if (cmover == -position) {stop()}
		   break;
		}
		case 'left':
		case 'right':
		{
		   move();
		   break;
		}
	}
	if(running) {
    xxx++;		
	setTimeout("status()",10);
    }	
target();
}

function slide() {

       rolling ();
	   
	   if(xxx>=period) {
	      crossdiss();
	   }
	   if((xxx==period)&&(s!='show')&&(s!='showall')&&(s!='stop')) {
          icont();
	   }
	   if (xxx>(period+cross)) {
		   xxx=0;
		   opacity=0;
		   
		   linkimg.href = fphoto + srcarray[j];
		   
   		   if (y==1) {y=2} else {y=1}
		   cslide(i);
		   if ((s=='show')||(s=='showall')) {s='stop'}
	   }
}
function stop() {
	i=j;
    if (opacity==0) {
	   running=false;
	   cslide(i);
    }
	else {
	crossdiss();
	s='stop';
	}
}
		
function show(z) {
	i=z;
	xxx=period;
	cslide(i)
	
	linkimg.href = fphoto + srcarray[i];
	if (s=='start') {s='showall'}
	else {s='show'}
	running=true;
	status();
}
		
function run() {
	if(!running) {
		running=true;
		s='slide';
		icont();
		xxx=period;
		status();
	}
}
function move(st) {
    if (st) {s=st;}
	if(!running) {
		running=true;
		status()
	} 
    if (opacity!=0) {slide()}
	else {
	   movercont();
	   if (mover<((width/carray)/20)) {mover = ((width/carray)/20)}
	   if (s=='right') {mover=-mover;}
	   rolling();
	   if (xxx>20) {
	      if (s=='right') {i--;i--;}
          icont();
	      jcont();
          linkimg.href = fphoto + srcarray[j];
          cslide();
		  if (y==2) {slide2.src = slide_img[j].src}
	      else {slide1.src = slide_img[j].src}
	      xxx=0;
	   }
	}
}
//function target() {document.getElementById('target').innerHTML = "i = "+i + " j = "+j + " | array = " + carray + " | " + " | array ="+ (carray-1) + " xxx ="+ xxx + "<br />  opacity ="+ opacity + "<br />  width ="+ width  + "  s = "+ s + "<br />   mover = "+ mover  + "<br />  startroll = "+ startroll+ "<br /> countmover = "+ countmover+ "<br /> position = "+ position+ "<br /> id1.style.left = " + id1.style.left + "<br /> id2.style.left = " + id2.style.left + "<br /> s = " + s + "<br /> y = "+ y + "<br /> slide1.src = " + slide1.src.substr(78) + " " + slide1.style.filter + "<br /> slide2.src = " + slide2.src.substr(78) + " " + slide2.style.filter + "<br /> running = "+ running + "<br /> linkimg.href = "+ linkimg.href; }
function target() {
document.getElementById('target').innerHTML = "slide "+eval(j+1) + " di " + carray + "<br />" + srcarray[j].substring(4,srcarray[j].length-4);
}
