cox=Array(); //co-ord x array
x=0; //current x
tx=0; //target x
action='';
totimg=0;
cimg=0;
doautoplay=1;
tr=Array();

thumbid=0;

spd=Array(1,2,4,8,14,20,30,40,51,60,100,130,130,100,100,51,40,30,20,14,8,4,2,1); //NEEDS TO EQUAL FULL WIDTH
spdid=0;

tmv=0;

function slideshow_ini(tot){
	
	totimg=tot;
	
	for(i=0;i<tot;i++){ cox[i]=(960*i)*-1;	}
	
	sstmr=setTimeout(slideshow_tmr,3000000);

}

function slideshow_tmr(){
	
	if(action==''){
		
		action='move';
		
		cimg++;
		if(cimg==totimg) cimg=0;
	
		tx=cox[cimg];
	
		if(tx<x) slideshow_asc();
		else if(tx>x) slideshow_desc();
		
	}
		
}

function slideshow_nxt(){
	
	if(action==''){
		
		action='move';
		
		doautoplay=0;	
		clearTimeout(sstmr);

		cimg++;
		if(cimg==totimg) cimg=0;
	
		tx=cox[cimg];
	
		if(tx<x) slideshow_asc();
		else if(tx>x) slideshow_desc();
		
	}
		
}



function slideshow_prv(){
	
	if(action==''){
		
		action='move';
		
		doautoplay=0;	
		clearTimeout(sstmr);

		cimg--;
		
		if(cimg==-1){
			cimg=(totimg-1);

			var s=document.getElementById('slideshow');
			s.style.left=cox[cimg]+"px";
			x=cox[cimg];
			cimg--;
		}
	
		tx=cox[cimg];
	
		if(tx<x) slideshow_asc();
		else if(tx>x) slideshow_desc();
		
	}
		
}



function slideshow_asc(){
	
	var s=document.getElementById('slideshow');
	
	px=spd[spdid];
	spdid++;	
	
	x=x-px;
	s.style.left=x+"px";
	
	if(tx<x){
		tmrasc=setTimeout(slideshow_asc,20);
	}else{
		
		islastimg=cimg+1;
		if(islastimg==totimg){
			x=0;
			cimg=0;
			s.style.left=x+"px";
		}
		
		action='';
		spdid=0;
		if(doautoplay==1) sstmr=setTimeout(slideshow_tmr,3000);
	}
	
}

function slideshow_desc(){
	
	var s=document.getElementById('slideshow');
	
	px=spd[spdid];
	spdid++;
	
	x=x+px;
	s.style.left=x+"px";
	
	if(tx>x){
		tmrdesc=setTimeout(slideshow_desc,20);
	}else{
		action='';
		spdid=0;
		if(doautoplay==1) sstmr=setTimeout(slideshow_tmr,3000);
	}
	
}

function slideshow_thumb(img,tid){
	
	if(action==''){
		
		thumbid=tid;
		
		action='move';
		
		doautoplay=0;	
		clearTimeout(sstmr);
		
		document.getElementById('slideshow_thumb_src').src=img;
	
		thumbx=960;
		spdid=0;
		
		slideshow_movethumb();
		
	}

}

function slideshow_movethumb(){
	
	px=spd[spdid];
	spdid++;	
	
	thumbx=thumbx-px;
	x=x-px;
	
	var s=document.getElementById('slideshow');
	s.style.left=x+"px";
	
	var s=document.getElementById('slideshow_thumb');
	s.style.left=thumbx+"px";
	
	if(thumbx!=0){
		tmrmve=setTimeout(slideshow_movethumb,20);
	}else{
		
		var s=document.getElementById('slideshow');
		s.style.left=cox[thumbid]+"px";
		x=cox[thumbid];
		cimg=thumbid;
		
		var s=document.getElementById('slideshow_thumb');
		s.style.left="700px";
		
		action='';
		spdid=0;
		
	}
	
}

thumbimg=Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
thumbimgalpha=Array(7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7);

function slideshow_thumb_glw(id,type){
	
	thumbimg[id]=type;

}

function slideshow_frame(){

	for(i=0;i<12;i++){
	
		if(thumbimg[i]==1){
		
			if(thumbimgalpha[i]<10){
				
				thumbimgalpha[i]=thumbimgalpha[i]+0.2;
				
				sstimgzz=document.getElementById('sstimg'+i)
			 	sstimgzz.style.opacity = thumbimgalpha[i]/10;
				sstimgzz.style.filter = 'alpha(opacity=' + thumbimgalpha[i]*10 + ')';
				
			}
		
		}else{
			
			if(thumbimgalpha[i]>7){
				
				thumbimgalpha[i]=thumbimgalpha[i]-0.2;

				sstimgzz=document.getElementById('sstimg'+i)
			 	sstimgzz.style.opacity = thumbimgalpha[i]/10;
				sstimgzz.style.filter = 'alpha(opacity=' + thumbimgalpha[i]*10 + ')';
				
			}
			
		}
	
	}

	thumbtmr=setTimeout(slideshow_frame,20);

}

thumbtmr=setTimeout(slideshow_frame,20);
