//create scrolling variable
if (!Scrolling) {
	var Scrolling = {};
}

//scroller constructor
Scrolling.Scroller = function (c, d, u, h) {
	
	//private variables
	var _self = this;
	var _timer = null;
	var _interval = 30;
	var _theight = c.offsetHeight+20;
	var _vheight = h;
	var _y = 0;
	
	//private functions
	_self.setPosition = function(y) {
		if (y < _vheight - _theight) {
			y = _vheight - _theight;
		}
		if (y > 0) {
			y = 0;
		}
		
		if (y == 0) {
			_self.disableUp();
		} else {
			_self.enableUp();
		}
		
		if (y == _vheight - _theight || _theight < _vheight) {
			_self.disableDown();
		} else {
			_self.enableDown();
		}
		
		_y = y;
		c.style.top = _y + "px";
	}
	
	_self.scrollWith = function(y) {
		_self.setPosition(_y - y);
	}
	
	_self.stopScroll = function() {
		if (_timer) {
			window.clearInterval(_timer);
		}
	}
	
	_self.disableUp = function() {
		u.src = "../image/up_arrow_d.gif";
	}
	
	_self.enableUp = function() {
		u.src = "../image/up_arrow.gif";
	}
	
	_self.disableDown = function() {
		d.src = "../image/down_arrow_d.gif";
	}
	
	_self.enableDown = function() {
		d.src = "../image/down_arrow.gif";
	}
	
	_self.startScroll = function (y) {
		_self.stopScroll();
		_timer = window.setInterval(function () { _self.scrollWith(y); }, _interval);
	}
	
	//init
	_self.setPosition(_y);
}
