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,100,110,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]=(810*i)*-1;	}
		
}

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(){
	
	//alert("1");
	
	if(action==''){
		
		//alert("2");
		
		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_load(id){
	

	gallery.start(0);
	
	/*var s=document.getElementById('site');
	s.style.height="100%";
	
	var m=document.getElementById('mask');
	m.style.display="block";
	
	var p=document.getElementById('slideshowholder');
	p.style.display="block";
	
	cimg=id-1;
	x=cox[cimg];
	document.getElementById('slideshow').style.left=cox[cimg]+"px";
	
	//sstmr=setTimeout(slideshow_tmr,3000);*/
	
}

function slideshow_close(){
	
	var s=document.getElementById('site');
	s.style.height="auto";
	
	var m=document.getElementById('mask');
	m.style.display="none";
	
	var p=document.getElementById('slideshowholder');
	p.style.display="none";
	
		
}

