function scrollDoc(id, dir, speed, keyboard){
	this.id=id;
	this.dir= (dir=='horizontal'||dir=='left')?{pos:'left', scroll: 'scrollLeft', size:'offsetWidth'}:
											   {pos:'top',  scroll: 'scrollTop',  size:'offsetHeight'};
											   
	this.speed=(this.speed)?this.speed:{sleep:10,step:10};
	this.keyboard= keyboard;
	var self=this;
	DOMReady(function(){
		self.init();
	})	
}

scrollDoc.prototype.init= function(){
	if (browser.msie&&!op.lock(this.id+'__init')) return;
		
	this.ul= DOM(this.id);
	this.li= this.ul.getElementsByTagName('li');
	if (!this.li.length) return false;
	
	this.setPos();
	this.current=0;
	
	var self=this;
	var onResize= function(){		
		self.setPos();
		self.moveTo(self.current);
	}
	
	if (window.addEventListener) {
	  window.addEventListener('resize', onResize, false);
	} else if (window.attachEvent) {
	  window.attachEvent('onresize', onResize);
	}
	

	var setActive=function(value){if (value){this.detachClass('disabled');} else {this.attachClass('disabled');}};
	
	this.next=DOM(this.id+'_next');
	this.next.listen('click', function(e){self.moveTo(self.current+1);});
	this.next.setActive= setActive;
	
	this.prev=DOM(this.id+'_prev');
	this.prev.setActive= setActive;
	this.prev.listen('click', function(e){self.moveTo(self.current-1);});
	this.prev.setActive(0);
	
	if (this.keyboard){
		DOM(null).listen('keyup', function(e){
			if (e.ctrlKey){
				if (e.keyCode==keyCode.left){
					return self.moveTo(self.current-1);					
				}
				else if (e.keyCode==keyCode.right){
					return self.moveTo(self.current+1);
				}
			}
			return true;
		});
	}
	
}

scrollDoc.prototype.setPos= function(){
	this.ul.style.position='relative';
	
	this.size=0;
	var maxWidth=0;
	for (var i=0; i<this.li.length; i++){	
		this.li[i].style['visibility']='hidden';
	}
	for (var i=0; i<this.li.length; i++){	
		
		this.li[i].style[this.dir.pos]=this.size+'px';
		this.li[i].style.position='absolute';
		this.li[i].style['visibility']='';
		this.size+=parseInt(this.li[i][this.dir.size]);
		maxWidth=Math.max(maxWidth, this.li[i][this.dir.size]);
	}
	this.ul.style.width=maxWidth+'px';
}

scrollDoc.prototype.moveTo= function(i){	
	if (i<0) return true;
	if (!this.li[i]) return true;
	
	if (!op.lock(this.id)) return true;
	this.current=i;
	this.prev.setActive((i>0)?1:0);
	this.next.setActive((i<this.li.length-1)?1:0);

	var self=this;
	op.animateRange(
			function(scroll){					
				self.ul[self.dir.scroll]=scroll;
			}, 
			function(){
				op.free(self.id)
			}, 
			this.ul[this.dir.scroll], 
			parseInt(this.li[i].style[this.dir.pos]), 
			this.speed.step, 
			this.speed.sleep, 
			null);
}

//scrollDoc.prototype.moveTo= function(i){
//	//out of range:	
//	//in progress:
//	if (this.interval) return false;
//	
//		
//	var self=this;
//	var scrollTo=parseInt(this.li[i].style[this.dir.pos]);
//	
//	this.interval= setInterval(function(){
//		
//		if (self.ul[self.dir.scroll]>scrollTo) self.ul[self.dir.scroll]-=self.speed.step;
//		else self.ul[self.dir.scroll]+=self.speed.step;
//		
//		if (Math.abs(self.ul[self.dir.scroll]-scrollTo)<self.speed.step){
//			self.ul[self.dir.scroll]=scrollTo;
//			clearInterval(self.interval);
//			self.interval=null;
//		}		
//	}, this.speed.sleep);
//}

scrollDoc.prototype.onListEnd= function(){}