//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 = 80;
	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/scroll_top.png";
	}
	
	_self.enableUp = function() {
		u.src = "../image/scroll_up.png";
	}
	
	_self.disableDown = function() {
		d.src = "../image/scroll_bottom.png";
	}
	
	_self.enableDown = function() {
		d.src = "../image/scroll_down.png";
	}
	
	_self.startScroll = function (y) {
		_self.stopScroll();
		_timer = window.setInterval(function () { _self.scrollWith(y); }, _interval);
	}
	_self.scrollWheel = function (event) {
		var delta = 0;
		if (!event) /* For IE. */
				event = window.event;
		if (event.wheelDelta) { /* IE/Opera. */
				delta = event.wheelDelta/120;
				/** In Opera 9, delta differs in sign as compared to IE.
				 */
				if (window.opera)
						delta = -delta;
		} else if (event.detail) { /** Mozilla case. */
				/** In Mozilla, sign of delta is different than in IE.
				 * Also, delta is multiple of 3.
				 */
				delta = -event.detail/3;
		}
		/** If delta is nonzero, handle it.
		 * Basically, delta is now positive if wheel was scrolled up,
		 * and negative, if wheel was scrolled down.
		 */
		if (delta)
				_self.scrollWith(-(delta*12));
		/** Prevent default actions caused by mouse wheel.
		 * That might be ugly, but we handle scrolls somehow
		 * anyway, so don't bother here..
		 */
		if (event.preventDefault)
				event.preventDefault();
		event.returnValue = false;

	}
	
	//init
	_self.setPosition(_y);
}

