var Scrollbar=function() { this.props = { container:null, content:null }; this.slider = new Array(); this.mousedown = false; this.init=function(container) { this.setup(container); }; this.setup=function(c) { this.props.container=document.getElementById(c); this.props.content=this.props.container.getElementsByTagName("div")[0]; this.props.container.style.position = "relative"; if($h(this.props.content)>$h(this.props.container)) { this.slider["height"] = parseInt(($h(this.props.container)/$h(this.props.content))*$h(this.props.container)); this.slider["ratio"] = ($h(this.props.content)-$h(this.props.container))/(153-this.slider.height); this.generateHTML(); } }; this.generateHTML=function() { var scrollbar = document.createElement("div"); scrollbar.id = "scrollbar"; var slider = document.createElement("div"); slider.id = "slider"; slider.onmousedown = scroller.md; slider.onmouseup = scroller.mu; slider.onmousemove = scroller.move; slider.onmouseout = scroller.blurred; slider.style.height=this.slider.height+"px"; slider.style.top = "0px"; scrollbar.appendChild(slider); this.props.container.appendChild(scrollbar); this.sliderelement = slider; }; this.md = function(e) { scroller.mousedown = true; scroller.mdpos = scroller.getMouseCoordinates(e); scroller.slider["top"] = parseInt(scroller.sliderelement.style.top); }; this.mu = function() { scroller.mousedown = false; }; this.blurred = function() { scroller.mousedown = false; }; this.move = function(e) { var st; scroller.mouse = scroller.getMouseCoordinates(e); if(scroller.mousedown && scroller.withinboundaries()) { diff = scroller.mouse.y-scroller.mdpos.y; st = scroller.slider.top; newposition = (diff+st); if(newposition<0) newposition=0; else if(newposition>(153-scroller.slider.height)) newposition = (153-scroller.slider.height); scroller.sliderelement.style.top = newposition+"px"; scroller.props.content.style.top = -(newposition*scroller.slider.ratio)+"px"; } else if(!scroller.withinboundaries()) { st = parseInt(scroller.sliderelement.style.top); if(st>0) scroller.sliderelement.style.top = (153-scroller.slider.height)+"px"; else scroller.sliderelement.style.top = "0px"; } }; this.withinboundaries=function() { var st = parseInt(scroller.sliderelement.style.top); var sb = scroller.slider.height+st; return (st>=0 && sb<=153)?true:false; }; this.getMouseCoordinates=function(e) { var m = new Array(); m["x"] = 0; m["y"] = 0; if(!e) var e = window.event; if (e.pageX || e.pageY) { m.x = e.pageX; m.y = e.pageY; } else if (e.clientX || e.clientY) { m.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; m.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } return m; }; }; var scroller = new Scrollbar();