var CUR = 0;
var sdir;

var _interval=null;
var _timeout=null;
var didMove=false;

function startScroll(dd){
	sdir=0;
	sdir=parseInt(dd);
	_timeout = setTimeout(doScroll,300);
}

function doScroll(){
	_timeout=null;
	if(_interval != null) clearInterval(_interval);	
	_interval=setInterval(move,10);
}

function stopScroll(){
	if(_interval!=null){
		clearInterval(_interval);
		_interval=null;
	}
	if(_timeout!=null) {
		clearTimeout(_timeout);
		_timeout=null;
	}
	if(didMove==false){
		old = CUR;
		CUR += sdir;
		if(CUR < 0) {
			CUR = 0;
		} else if (CUR > max) {
			CUR = max;
		} else {
			$e.move('sw_thumb','easeBoth',(CUR*-step),null,.3);
		}
		setArrows();
	}else {
		$e.move('sw_thumb','easeOut',(CUR*-step),null,.15);
		didMove=false;
		setArrows();
	}
	
}

function move(){
	didMove=true;
			
	var maxpos  = max*-step;
	var s = $e('sw_thumb');
	var cpos = parseInt(s.style.left);

	var pos = cpos -(sdir*15);

	if(pos < maxpos || pos > 0){
		pos = Math.bound(0,maxpos,pos);
		clearInterval(_interval);
		_interval=null;
		
	} else {
		s.style.left=pos+"px";

	}
	
	CUR = Math.abs(  (sdir == 1) ? Math.floor(cpos/step) : Math.ceil(cpos/step)  );
	
}

function setArrows(){
		var lao = (CUR==0)?0:1;
		var rao = (CUR==max)?0:1;
		$e.setStyle("swLArrow","opacity",lao);
		$e.setStyle("swRArrow","opacity",rao);
}



function imgOver(el,num){
	$e.move(el.getAttribute("id") ,"easeBoth",null,5,.1);
	$e("thumb_tip").innerHTML=el.firstChild.alt;
	$e.show("thumb_tip");
	//el.style.top="5px";
}

function imgOut(el,num){
	$e.move(el.getAttribute("id"),"easeBoth",null,0,.1);
	$e.hide("thumb_tip");
	//el.style.top="0px";
}