﻿function textScroller(strMasterContainer, strDocumentContainer, strArrowContainer) {
	
	this.scrollerobj = strDocumentContainer;
	this.masterobj = strMasterContainer;
	this.arrowobj = strArrowContainer;
	this.scrollheight = 0;
	this.movespeed = 2;
	this.movespeedfast = 6;
	this.intervalspeed = 1.0;
	this.bottompadding = 50;
	
	this.ileftpos = 0;
	this.timer = null;
	this.tempmove = 0;
	this.scheight = 0;
	this.sbtop;
	this.dragit = 0;
	this.fullscroll = 0;

  this.scrollDirection = 0;
}	

textScroller.prototype = {
 
	prepareScroller: function() { 
				this.scrollheight = parseInt(document.getElementById(this.masterobj).offsetHeight);
				if(document.getElementById(this.scrollerobj).offsetHeight-this.scrollheight>0) { 
					this.fullscroll = (parseInt(document.getElementById(this.scrollerobj).offsetHeight-this.scrollheight)*-1);
				}
				if(this.fullscroll < 0 && this.arrowobj != '') {
					//document.getElementById('arrowDiv1').style.left = rxpos('masterContainer_1') + g('masterContainer_1').offsetWidth + p(jsRF*6) + "px";
					//document.getElementById('arrowDiv1').style.top = rypos('masterContainer_1') + p(g('masterContainer_1').offsetHeight / 2) - (g('arrowDiv1').offsetHeight / 2) + "px";
					document.getElementById(this.arrowobj).style.visibility = "visible";
				}
		},


    doScroll: function(instance) {  
				return function() {
					//alert(instance.fullscroll);
					if(instance.fullscroll==0) { clearInterval(instance.timer); }
					var o = document.getElementById(instance.scrollerobj);
					instance.ileftpos += (instance.scrollDirection==0 ? - instance.tempmove : + instance.tempmove);
					
					o.style.top = instance.ileftpos + "px";
					
					var progress = parseInt(100 - ((((instance.fullscroll-instance.bottompadding) - (parseInt(o.style.top))) / (instance.fullscroll-instance.bottompadding)) * 100));
					if(instance.scrollDirection==0) {
							if(parseInt(o.style.top)<parseInt(instance.fullscroll-instance.bottompadding)) {  
								clearInterval(instance.timer);
								o.style.top = parseInt(instance.fullscroll-instance.bottompadding) + "px";
							}
					}
					else {
							if(parseInt(o.style.top)>0) {
								clearInterval(instance.timer);
								o.style.top = 0 + "px";
							}
					}
			};
		},
		
		scrollUp: function() {	
				this.tempmove = this.movespeed;
				if(parseInt(document.getElementById(this.scrollerobj).style.top) < 0) {
					this.scrollDirection = 1;
					this.timer = setInterval(this.doScroll(this), this.intervalspeed*10);
				}
		},
	
		scrollDown: function () { 
				var o = document.getElementById(this.scrollerobj);
				this.tempmove = this.movespeed;
				if(parseInt(o.style.top) > parseInt((o.offsetHeight*-1) + this.bottompadding)) {
					this.scrollDirection = 0;
					this.timer = setInterval(this.doScroll(this), this.intervalspeed*10);
				}	
		},
		
		alterSpeed: function(faster) {
				this.tempmove = (faster==1 ? this.movespeedfast : this.movespeed);
		},
		
    cancelScroll: function() { 
        clearInterval(this.timer); 
    } 
}; 
