cox=Array(); //co-ord x array
x=0; //current x
tx=0; //target x
action='';
totimg=0;
cimg=0;
doautoplay=1;
tr=Array();
mv=Array(30,20,20,20,20,15,10,10,10,5,5,5,2,2,2,2,1,1); //must equal a multiple of 30
tmv=0;

function slideshow_ini(tot){
	
	totimg=tot;
	
	for(i=0;i<tot;i++){ cox[i]=(690*i)*-1;	}
	
	for(i=0;i<mv.length;i++){
		tmv=tmv+mv[i];
	}
	
	for(i=0;i<mv.length;i++){
		tr[i]=tmv;
		tmv=tmv-mv[i];
	}
	
	sstmr=setTimeout(slideshow_tmr,8000);

}

function slideshow_tmr(){
	
	cimg++;
	if(cimg==totimg) cimg=0;
	
	slideshow_move(cimg,1);
		
}

function slideshow_move(id,type){
	
	if(type==2){
		doautoplay=0;	
		clearTimeout(sstmr);
	}
	
	if(action==''){
		action='move';
		tx=cox[id];
		
		for(i=0;i<totimg-1;i++){
			var n=document.getElementById('ssnav'+i);
			n.src="/images/ssnav_off.png";
		}
		
		if(id==(totimg-1)) ballid=0; else ballid=id;
		var n=document.getElementById('ssnav'+ballid);
		n.src="/images/ssnav.png";
		
		if(tx<x) slideshow_asc();
		else if(tx>x) slideshow_desc();
	}
	
}



function slideshow_asc(){
	
	var s=document.getElementById('slideshow');
	
	px=60;
	
	for(i=0;i<tr.length;i++){
		if(tx==(x-tr[i])) px=mv[i];
	}
	
	x=x-px;
	s.style.left=x+"px";
	
	if(tx<x){
		tmr=setTimeout(slideshow_asc,20);
	}else{
		islastimg=cimg+1;
		if(islastimg==totimg){
			x=0;
			cimg=0;
			s.style.left=x+"px";
		}
		action='';
		if(doautoplay==1) sstmr=setTimeout(slideshow_tmr,8000);
	}
	
}

function slideshow_desc(){
	
	var s=document.getElementById('slideshow');
	
	px=60;
	
	for(i=0;i<tr.length;i++){
		if(tx==(x+tr[i])) px=mv[i];
	}
	
	x=x+px;
	s.style.left=x+"px";
	
	if(tx>x){
		tmr=setTimeout(slideshow_desc,20);
	}else{
		action='';
		if(doautoplay==1) sstmr=setTimeout(slideshow_tmr,8000);
	}
	
}
