var scrollContentList = new Array();

var ScrollContent = Class.create();

ScrollContent.prototype = {
	initialize: function(contentId, btnUpId, btnDownId){
		this.moveupvar = null;
		this.movedownvar = null;
		this.contentHeight = 0;
		this.speed = 3;

		this.eContent = document.getElementById(contentId);
		this.eBtnUp = document.getElementById(btnUpId);
		this.eBtnDown = document.getElementById(btnDownId);
	},


	render: function(){
		this.eContent.style.position = "absolute";
		this.eContent.style.top = 0;
		this.eContent.style.left = 0;
		this.contentHeight = this.eContent.offsetHeight;

		Event.observe(this.eBtnUp, 'mouseover', this.moveupEventHandler.bindAsEventListener(this));
		Event.observe(this.eBtnUp, 'mouseout', this.clearTimeOutHandler.bindAsEventListener(this));

		Event.observe(this.eBtnDown, 'mouseover', this.movedownEventHandler.bindAsEventListener(this));
		Event.observe(this.eBtnDown, 'mouseout', this.clearTimeOutHandler.bindAsEventListener(this));
	},

	moveupAction: function(scrollObject){		
		if (parseInt(scrollObject.eContent.style.top)<0)
				scrollObject.eContent.style.top=parseInt(scrollObject.eContent.style.top) + scrollObject.speed + "px";	

		var timeoutFunc = function() {
			scrollObject.moveupAction(scrollObject);			
		}
		scrollObject.moveupvar = setTimeout(timeoutFunc, 20);
	},

	movedownAction: function(scrollObject){		
		if (parseInt(scrollObject.eContent.style.top)>=(scrollObject.contentHeight*(-1)+110))
				scrollObject.eContent.style.top=parseInt(scrollObject.eContent.style.top) - scrollObject.speed + "px";

		var timeoutFunc = function() {			
			scrollObject.movedownAction(scrollObject);
		}
		scrollObject.movedownvar = setTimeout(timeoutFunc, 20);
	},

	moveupEventHandler: function(event){	
		var thisObj = this;
		thisObj.moveupAction(thisObj);
	},

	movedownEventHandler: function(event){		
		var thisObj = this;
		thisObj.movedownAction(thisObj);		
	},

	clearTimeOutHandler: function(event){		
		var ele;
		if ( document.all ) {
			ele = event.srcElement;			
		}
		if ( !document.all ) {
			ele = event.target;
		}	

		if(ele.id == this.eBtnUp.id){			
			clearTimeout(this.moveupvar);
		}
		if(ele.id == this.eBtnDown.id){
			clearTimeout(this.movedownvar);
		}
	}
};

function initScrollContents(config){	
	for (var id in config){
		var scrollContentItem = new ScrollContent(config[id]["contentId"], config[id]["btnUpId"], config[id]["btnDownId"]);
		scrollContentList[scrollContentList.length] = scrollContentItem;
	}

	for(var i=0; i<scrollContentList.length; i++){
		scrollContentList[i].render();
	}
}