RightBox = {
	init: function () {
		this.box = document.getElementById('right_column');
		this.scrollStep = 15;
		if (this.box.offsetHeight < this.box.scrollHeight) {
			this.arrup = document.createElement ('div');
			this.arrup.className = 'btn_scroll_up';
			this.arrup.onmousedown = function () {RightBox.startScrolling('up'); };
			this.arrup.onmouseup = function () {RightBox.stopScrolling(); };
			
			this.arrdown = document.createElement ('div');
			this.arrdown.className = 'btn_scroll_down';
			this.arrdown.onmousedown = function () {RightBox.startScrolling('down'); };
			this.arrdown.onmouseup = function () {RightBox.stopScrolling(); };
			
			this.box.parentNode.appendChild (this.arrup);
			this.box.parentNode.appendChild (this.arrdown);
			this.box.className += ' with_scroll';
			
			this.onTimerBinded = function () { RightBox.onTimer(); };
			this.onMouseWheelBinded = function (event) { RightBox.onMouseWheel(event); } ;
			
			if (this.box.addEventListener) {
				this.box.addEventListener ('mousewheel', this.onMouseWheelBinded, true);
				this.box.addEventListener ('DOMMouseScroll', this.onMouseWheelBinded, true);
			}
			else if (this.box.attachEvent) {
				this.box.attachEvent ('onmousewheel', this.onMouseWheelBinded);
				this.box.attachEvent ('onDOMMouseScroll', this.onMouseWheelBinded);
			}
		}
	},
	startScrolling: function (direction) {
		if (this.scrolling)
			this.stopScrolling();
		else {
			this.scrollDirection = direction;
			if (!this.doScroll())
				return;
			setTimeout(this.onTimerBinded, 600);
			this.scrolling = true;
		}
	},
	doScroll: function () {
		if (this.scrollDirection == 'up') {
			if (this.box.scrollTop < 1)
				return false;
			this.box.scrollTop = Math.max (0, this.box.scrollTop - this.scrollStep);
		} else {
			if (this.box.scrollTop > this.box.scrollHeight - this.box.offsetHeight - 1)
				return false;
			this.box.scrollTop = Math.max (0, this.box.scrollTop + this.scrollStep);
		}
		return true;
	},
	onTimer: function () {
		if (this.scrolling) {
			if (this.doScroll()) {
				setTimeout(this.onTimerBinded, 60);
			} else {
				this.stopScrolling();
			}
		}
	},
	stopScrolling: function () {
		if (this.scrolling)
			this.scrolling = false;
	},
	onMouseWheel: function (event) {
		var event = event || window.event || document.event;
		if (!event) return;
		if (event.wheelDelta) {
			var delta = event.wheelDelta;
			if (window.opera) delta = -delta;
		} else if (event.detail) {
			var delta = -event.detail / 3; 
		} else 
			return;
		if (delta < 0) {
			this.scrollDirection = 'down';
		} else if (delta > 0)
			this.scrollDirection = 'up';
		else
			return;
		this.doScroll();
		if (event.preventDefault) {
			event.preventDefault();
			event.stopPropagation();
	    } else {
			event.returnValue = false;
			event.cancelBubble = true;
	    }
	}
}

RightBox.init();