var ffuk = {

	scroller: {
		elementId: null,
		element: null,
		position: 0,
		positions: {},
		intervalId: 0,
		scrollWait: 50,
		scrollIncrement: 20,

		prepareScroll: function(id) {
			this.element = null;
			this.elementId = id;
			if (typeof this.positions[id] == 'undefined')
				this.positions[id] = 0;

			this.position = this.positions[id];
		},

		scroll: function() {
			// hide the functions
		},

		makeUpDown: function(elementId, arrowId, funcName) {
			var elm = document.getElementById(arrowId);
			if (elm && !elm.onmousedown) {
				elm.onmousedown = function(){};
				var me = this;
				var p = document.getElementById(elementId);
				var p = p.parentNode;
				lightCore.registerInit({
					initialize: function() {
						if (p && p.scrollTop) {
							me.prepareScroll(elementId);
							me.setPosition(-p.scrollTop);
							p.scrollTop = 0;
							me.endScroll();
						}
					}
				});
				var mousedown = function(event) {
					if (event.stopPropagation) event.stopPropagation();
					if (event.preventCapture) event.preventCapture();
					if (event.preventBubble) event.preventBubble();
					me[funcName](elementId);
				};
				var mouseend = function(event) { me.endScroll(); };
				if (elm.addEventListener) {
					elm.addEventListener('mousedown', mousedown, true);
					elm.addEventListener('mouseout', mouseend, true);
					elm.addEventListener('mouseup', mouseend, true);
				} else if (elm.attachEvent) {
					elm.attachEvent('onmousedown', mousedown);
					elm.attachEvent('onmouseout', mouseend);
					elm.attachEvent('onmouseup', mouseend);
				}
			}
		},

		makeUp: function(elementId, arrowId) {
			this.makeUpDown(elementId, arrowId, 'scrollUp');
		},

		makeDown: function(elementId, arrowId) {
			this.makeUpDown(elementId, arrowId, 'scrollDown');
		},

		scrollUp: function(id, element) {
			this.prepareScroll(id, element);
			this.startScrolling(this.scrollIncrement);
		},

		scrollDown: function(id, element) {
			this.prepareScroll(id, element);
			this.startScrolling(-this.scrollIncrement);
		},

		startScrolling: function(increment) {
			var me = this;
			this.intervalId = setInterval(function(){
				me.setPosition(me.position + increment);
			}, this.scrollWait);
		},

		endScroll: function() {
			clearInterval(this.intervalId);
			this.positions[this.elementId] = this.position;
		},

		getElement: function() {
			if (!this.element)
				this.element = document.getElementById(this.elementId);
			return this.element;
		},

		reset: function() {
			if (this.elementId)
				this.endScroll();
			this.elementId = null;
			this.positions = {};
			this.element = null;
		},

		setPosition: function(value) {
			var elm = this.getElement();
			if (value > 0) {
				value = 0;
			} else {
				var fullHeight = elm.scrollHeight + 50;
				var visibleHeight = elm.parentNode.clientHeight;
				if (fullHeight+value < visibleHeight) {
					value = Math.min(-(fullHeight-visibleHeight), 0);
				}
			}
			elm.style.marginTop = value + 'px';
			this.position = value;
		}
	}
};
