var identifier = 'slider';
/*
var movingTime = 30;  delay time between frame changing - in ms
var scrollInterval = 2500; delay between items scrolling 
var startMoveTo = 'right'; where we move at the start ( right | left )
var saveMovingDirection = true; continue moving on user-selected direction
*/

var movingDirection  = null;
var moveTo = null;

function init_slider(){
	
	var a24_scroll_list = document.getElementById('a24-slider');
	var a24_scroll_ctrl = null;
	
	try{
		a24_scroll_list.onmouseout = function(){startScroll()}
		a24_scroll_list.onmouseover = function(){stopScroll()}
	}catch(e){}
	
	startScroll();
}

function slideRight() {
	
	var slides = document.getElementById(identifier).getElementsByTagName("li");

	var slidesContainer = slides[0].parentNode;
	var mover = slides[0];
	var firstelement = slides[1];
	var firstRegularSlide = slides[1];
	var moverWidth = mover.offsetWidth;
	
	if(movingDirection =='left'){
		 return false;
	}
	
	if (moverWidth > 4)moverWidth -= moveBy;/* move by 4px*/
	else moverWidth = 0;
	

	mover.style.width = moverWidth + "px";
	
	
	 if (moverWidth > 0){
	        
		 setTimeout(function() {slideRight();}, movingTime);
		 movingDirection = 'right';
		 
		 if(saveMovingDirection == true){
			 moveTo = movingDirection;
		 }
		 
	 }else {
	        
	     slidesContainer.insertBefore(firstRegularSlide, null);
	     mover.style.width = firstelement.offsetWidth + "px";
	     movingDirection = 'stopped';
	}
}

function slideLeft() {
    
 var slides = document.getElementById(identifier).getElementsByTagName("li");
 
 var slidesContainer = slides[0].parentNode;
 var mover = slides[0];
 var firstRegularSlide = slides[1];
 var firstWidth = firstRegularSlide.offsetWidth;
 
 if(movingDirection =='right'){
	 return false;
 }
 
 if (mover.offsetWidth == firstWidth) {
 
     var lastRegularSlide = slides[slides.length - 1];
         
     mover.style.width = "0px";
     slidesContainer.insertBefore(lastRegularSlide, firstRegularSlide);
 }
 
 var moverWidth = mover.offsetWidth;
 
 if (firstWidth - moverWidth > 4) moverWidth += moveBy;
 else moverWidth = firstWidth;
 
 mover.style.width = moverWidth + "px";	
 
 if (moverWidth < firstWidth) {
	setTimeout(function() {slideLeft();}, movingTime);
	movingDirection  = 'left';
	
	if(saveMovingDirection == true){
		 moveTo = movingDirection;
	}
	
 }else{
	 movingDirection  = 'stopped';
 }
    
} 

function startScroll(){
	if(!moveTo){
		moveTo = startMoveTo;
	}
	if(moveTo == 'left'){
		a24_scroll_ctrl = setInterval(function() {slideLeft();},scrollInterval);
	}else{
		a24_scroll_ctrl = setInterval(function() {slideRight();},scrollInterval);
	}
}

function stopScroll(){
	clearInterval(a24_scroll_ctrl);
}

