function scrollableDiv(divid)
{
	var curmoveval=0; //Текущее положение
	
	var MIN_SPEED=1; //Обычная скорость
	var MAX_SPEED=4; //Максимальная скорость
	var speed= MIN_SPEED; //Текущая скорость
	var crossobj = document.getElementById(divid); //Область скролла
	var contentheight = crossobj.offsetHeight; //Его высота
	var scrollheight = crossobj.offsetParent.offsetHeight; //Высота видимой части
	this.moveTime = 20; //Интервал между вызовами функции
	this.timeOutVarUp; //Значение для интервала
	this.timeOutVarDown; //Значение для интервала
	var ourScroll = false;
	var ourScrollHeight = false;
	var visibleHeight = false;
 
	//Остановка
	this.alterSpeed = function(smin, smax){
		MIN_SPEED = smin;
		MAX_SPEED = smax;
		speed = MIN_SPEED;
	}
	
	//Остановка
	this.stopMoving = function(){
		this.deleteTimeOut();
		speed=MIN_SPEED;	
	}
	
	//Установка максимальной скорости
	this.boostMoving = function(){
		speed=MAX_SPEED;	
	}
	
	//Установка стандартной скорости
	this.normalMoving = function(){
		speed=MIN_SPEED;	
	}
	
	//Двигаем вниз
	this.moveDown = moveDown;
	function moveDown() {//alert('1');
		//contentheight = crossobj.offsetHeight;	
		//this.calculateScrollOffset();
		if (curmoveval>=(contentheight*(-1)+scrollheight-10)){
			crossobj.style.top=(curmoveval-speed)+'px';
			curmoveval -= speed;
		}
		else
			$(ourScroll).css("top", ourScrollHeight + "px");
		
		this.giveTimeOut(false); 
	}
	
	//Двигаем вверх
	this.moveUp = moveUp;
	function moveUp(){
		//contentheight = crossobj.offsetHeight;	
		//this.calculateScrollOffset();
		if (curmoveval<=0){
			crossobj.style.top=(curmoveval+speed)+'px';
			curmoveval += speed;
		}
		
		this.giveTimeOut(true); 
	}

	//Перестаем вызывать функцию
	this.deleteTimeOut = function(){
		clearTimeout(this.timeOutVarUp);
		clearTimeout(this.timeOutVarDown);
	}
	
	//Установка интервала движения
	this.giveTimeOut = function(movingup){
		var scrollableDivClass = this;
		
		if(movingup)
			scrollableDivClass.timeOutVarUp = setTimeout(function(){scrollableDivClass.moveUp();}, scrollableDivClass.moveTime); 
		else
			scrollableDivClass.timeOutVarDown = setTimeout(function(){scrollableDivClass.moveDown();}, scrollableDivClass.moveTime); 
	}
	
	/*function calculateOffset(pos){
		var out = 0;
		
		var tmp = ((contentheight - scrollheight + 10) * pos) / ourScrollHeight;
		out = Math.round(tmp);
		return out;
	}
	
	this.calculateScrollOffset = function(){
		var out = 0;
		
		var tmp = ((scrollheight * ((-1)*curmoveval)) / (contentheight - scrollheight)) - 175;
		out = Math.round(tmp);
		if(out < 0)
			out = 0;
		$(ourScroll).css("top", out + "px");
	}*/
	
	/*this.dragMe = dragMe;
	function dragMe(y11){
		if(!ourScroll)
			return;
	
		//$(ourScroll).html(y);
		//$(ourScroll).html('-' + y11 +'px');
		//moveDown();
		var offset = (-1)*calculateOffset(y11);
		curmoveval = offset;
		crossobj.style.top=offset +'px';
		
		
		
	}*/
	
	/*this.setScroll = function(s_bar){
		ourScroll = '#' + s_bar;
		
		$(document).ready(function(){
			$(ourScroll).Draggable(
				{
					zIndex: 	1000,
					ghosting:	false,
					opacity: 	0.8,
					containment : 'parent',
					axis:	'vertically',
					onDrag: function(x,y){
					
						dragMe(y);
						
						$(ourScroll).css("cursor", "pointer");
					
					}
				}
			);
			curmoveval = 1;
			ourScrollHeight = $(ourScroll).parent().height() - $(ourScroll).height();
			//visibleHeight = $(crossobj).parent().height();alert(visibleHeight);
		});
	}*/
}


