var scroller = function () {
	
	this.init = function (objId,oScrollingC,oScrolling,oScrollerA,oScrollerC,oScroller,bVert,bContentDrag,bScrollerB,oScrollHome,oScrollAway,scrollInc,jumpGap,minScrollLen,correction) {
		
		this.gRef = "Scroller_"+objId;
		
		this.bVert = bVert;
		
		eval(this.gRef+" = this");
		
		this.oScroller = oScroller;
		this.oScrollerC = oScrollerC;
		this.oScrolling = oScrolling;
		this.scrollInc = scrollInc;
		this.correction = correction;
		
		bVert ? this.docLen = oScrolling.offsetHeight : this.docLen = oScrolling.offsetWidth;
		bVert ? this.contLen = oScrollingC.offsetHeight : this.contLen = oScrollingC.offsetWidth;
		bVert ? this.scrollAreaLen = oScrollingC.offsetHeight : this.scrollAreaLen = oScrollingC.offsetWidth;
		
		// alert(this.docLen + ' ' + this.contLen + ' ' + this.scrollAreaLen);
		
		// the length of the content is less than the length of the container, we don't need the scrollbar
		if (this.docLen >= this.contLen) {
			
			this.scrollLen = (this.contLen * this.scrollAreaLen) / this.docLen;
			if (this.scrollLen < minScrollLen) {
				this.scrollLen = minScrollLen;
				}
			
			if (bVert) {
				oScroller.style.height = Math.round(this.scrollLen) + "px";
				}
			else {
				oScroller.style.width = Math.round(this.scrollLen) + "px";
				}
				
			this.scrollDist = Math.round(this.scrollAreaLen-this.scrollLen-correction);
			this.docScrollDist = Math.round(this.docLen-this.contLen);
			
			bVert ? oScroller.style.top = "0px" : oScroller.style.left = "0px";
			bVert ? oScrolling.style.top = "0px" : oScrolling.style.left = "0px";
			
			if (bVert) {
				
				minX = 0;
				maxX = 0;
				minY = 0;
				maxY = this.scrollDist;
				
				minX2 = 0;
				maxX2 = 0;
				minY2 = -this.docScrollDist;
				maxY2 = 0;
				
				}
			else {
				
				minX = 0;
				maxX = this.scrollDist;
				minY = 0;
				maxY = 0;
				
				minX2 = -this.docScrollDist;
				maxX2 = 0;
				minY2 = 0;
				maxY2 = 0;
				
				}
				
			var scrollerobj = this;	
			
			// make the scroller draggable
	    	Drag.init(oScroller,null,minX,maxX,minY,maxY);
			
			// add ondrag functions
			oScroller.onDrag = function (x,y) {
				bVert ? scrollXY = parseInt(oScroller.style.top) : scrollXY = parseInt(oScroller.style.left);
			    docXY = 0 - (scrollXY * (scrollerobj.docLen - scrollerobj.contLen) / scrollerobj.scrollDist);
			   	bVert ? oScrolling.style.top = docXY + "px" : oScrolling.style.left = docXY + "px";
			    }
			
			// make the thing itself also draggable
			if (bContentDrag) {
				Drag.init(oScrolling,null,minX2,maxX2,minY2,maxY2);
				// add ondrag functions
				oScrolling.onDrag = function (x,y) {
					bVert ? scrollXY = parseInt(oScrolling.style.top) : scrollXY = parseInt(oScrolling.style.left);
				    docXY = 0 - (scrollXY * (scrollerobj.scrollAreaLen-scrollerobj.scrollLen-correction) / scrollerobj.docScrollDist);
					bVert ? oScroller.style.top = docXY + "px" : oScroller.style.left = docXY + "px";
				    }
				}
			// scrollerobj.increment(bVert,true);
			// scrollerobj.increment(bVert,false);
			if (bScrollerB) {
				
				oScroller.onclick = function (e) {
					if (!e) var e = window.event
					e.cancelBubble = true;
					return false;
					}
			
				oScrollHome.onclick = function(e) {
					if (!e) var e = window.event
					e.cancelBubble = true;
					return false;
					}
					
				oScrollAway.onclick = function(e) {
					if (!e) var e = window.event
					e.cancelBubble = true;
					return false;
					}
							
				oScrollHome.onmousedown = function() {
					scrollerobj.scrollhome();
					}
					
				oScrollHome.onmouseup = function() {
					scrollerobj.stopscroll();
					}
					
				oScrollHome.onmouseout = function() {
					scrollerobj.stopscroll();
					}
					
				oScrollAway.onmousedown = function() {
					scrollerobj.scrollaway();
					}
					
				oScrollAway.onmouseup = function() {
					scrollerobj.stopscroll();
					}
					
				oScrollAway.onmouseout = function() {
					scrollerobj.stopscroll();
					}
					
				oScrollerA.onclick = function(e) {
					
					if (!e) var e = window.event
					
					bVert ? scrollXY = parseInt(oScroller.style.top) : scrollXY = parseInt(oScroller.style.left);
					bVert ? scrollingXY = parseInt(oScrolling.style.top) : scrollingXY = parseInt(oScrolling.style.left);
					bVert ? scrollAreaXY = parseInt(oScrollerA.style.top) : scrollAreaXY = parseInt(oScrollerA.style.left);
					
					var scrollJump = parseInt(jumpGap * (scrollerobj.scrollAreaLen-scrollerobj.scrollLen) / scrollerobj.docScrollDist);
					
					if (e.offsetX === undefined) {
						bVert ? clientXY = e.layerY : clientXY = e.layerX;
						}
					else {
						bVert ? clientXY = e.offsetY : clientXY = e.offsetX;
						}
					
					if (clientXY < scrollXY) {
						
						var newscrollXY = scrollXY - scrollJump;
						var newcontentXY = scrollingXY + jumpGap;
						
						if (scrollXY < scrollJump) {
							var newscrollXY = 0;
							var newcontentXY = 0;
							}
						
						bVert ? oScroller.style.top = newscrollXY + "px" : oScroller.style.left = newscrollXY + "px";
						bVert ? oScrolling.style.top = newcontentXY + "px" : oScrolling.style.left = newcontentXY + "px";
						
						}
					else {
						
						var newscrollXY = scrollXY + scrollJump;
						var newcontentXY = scrollingXY - jumpGap;
						
						// alert((scrollXY + scrollerobj.scrollLen) + ' :: ' + (scrollerobj.scrollAreaLen - scrollJump - scrollerobj.correction));
						
						if ((scrollXY + scrollerobj.scrollLen) > (scrollerobj.scrollAreaLen - scrollJump - scrollerobj.correction)) {
							var newscrollXY = scrollerobj.scrollAreaLen - scrollerobj.scrollLen - scrollerobj.correction;
							var newcontentXY = Math.round(0 - (newscrollXY * (scrollerobj.docLen - scrollerobj.contLen) / scrollerobj.scrollDist));
							}
						
						bVert ? oScroller.style.top = newscrollXY + "px" : oScroller.style.left = newscrollXY + "px";
						bVert ? oScrolling.style.top = newcontentXY + "px" : oScrolling.style.left = newcontentXY + "px";
						
						}
					
					}
				
				}
			oScrollerC.style.display = "block";
			}
		else {
			oScrollerC.style.display = "none";
			}
		
		}
		
	this.increment = function(bHome) {
		
		bVert = this.bVert;
		
		bVert ? scrollXY = parseInt(this.oScroller.style.top) : scrollXY = parseInt(this.oScroller.style.left);
		bVert ? scrollingXY = parseInt(this.oScrolling.style.top) : scrollingXY = parseInt(this.oScrolling.style.left);
	
		var scrollby = parseInt(this.scrollInc * (this.scrollAreaLen-this.scrollLen) / this.docScrollDist);
		
		if (bHome) {
			
			if (scrollXY > scrollby) {
				var newscrollXY = scrollXY - scrollby;
				var newcontentXY = scrollingXY + this.scrollInc;
				}
			else {
				var newscrollXY = 0;
				var newcontentXY = 0;
				}
			
			bVert ? this.oScroller.style.top = newscrollXY + "px" : this.oScroller.style.left = newscrollXY + "px";
			bVert ? this.oScrolling.style.top = newcontentXY + "px" : this.oScrolling.style.left = newcontentXY + "px";
			
			}
		else {
			
			if (scrollXY < (this.scrollAreaLen - this.scrollLen - scrollby - this.correction)) {
				var newscrollXY = scrollXY + scrollby;
				var newcontentXY = scrollingXY - this.scrollInc;
				}
			else {
				var newscrollXY = this.scrollAreaLen - this.scrollLen - this.correction;
				var newcontentXY = Math.round(0 - (newscrollXY * (this.docLen - this.contLen) / this.scrollDist));
				}
			
			bVert ? this.oScroller.style.top = newscrollXY + "px" : this.oScroller.style.left = newscrollXY + "px";
			bVert ? this.oScrolling.style.top = newcontentXY + "px" : this.oScrolling.style.left = newcontentXY + "px";
					
			}
		
		
		}
	
	}
	
scroller.prototype.scrollhome = function() {
	gTimerId = window.setInterval(this.gRef + ".increment(true)", 100);
	}
	
scroller.prototype.scrollaway = function() {
	gTimerId = window.setInterval(this.gRef + ".increment(false)", 100);
	}
	
scroller.prototype.stopscroll = function() {
	try {
		window.clearInterval(gTimerId);
		}
	catch (e) {}
	}