ThreeOhScroll.mo5 = navigator.userAgent.indexOf("Gecko") != -1
ThreeOhScroll.ie4 = navigator.appName == "Microsoft Internet Explorer" && document.all
ThreeOhScroll.ie5 = navigator.appName == "Microsoft Internet Explorer" && document.getElementById
ThreeOhScroll.pc = navigator.platform == "Win32"
ThreeOhScroll.ie4pcDescWidth = 100
ThreeOhScroll.mozAdjust = ThreeOhScroll.mo5 ? 75 : 0
ThreeOhScroll.aniLen = 250


function ThreeOhScroll(id)
{
	if (ThreeOhScroll.mo5 || (ThreeOhScroll.ie4 && ThreeOhScroll.pc) || ThreeOhScroll.ie5) {
		this.id = id
		this.getMembers()
		this.clipH		= parseInt(this.container.style.height)
		this.PTags		= ypGetDescendantsByTagName("H", this.content)
		var lastP		= this.PTags[this.PTags.length-1]
		var lastPTop	= lastP.offsetTop - ThreeOhScroll.mozAdjust
		this.docH		= lastPTop + Math.max(lastP.offsetHeight, this.clipH)
		this.scrollH	= this.docH - this.clipH
		this.thumbMax	= parseInt(this.thumbContainer.style.height) - this.thumbImg.height		
		this.gRef = "ThreeOhScroll_"+id
		eval(this.gRef+"=this")
		this.thumb.obj	= this
		this.thumbdown.obj=this
		this.thumbup.obj=this
		
		
		this.thumbdown.onmouseover = this.setDownStyle
		this.thumbdown.onmousedown= this.startDown
		this.thumbdown.onmouseup= this.stopDown
		
		this.thumbup.onmouseover = this.setUpStyle
		this.thumbup.onmousedown= this.startUp
		this.thumbup.onmouseup= this.stopUp
				
		this.thumb.onmousedown = this.startDrag
		this.thumb.ondragstart = function() { return false }
	} else {
		alert ('Sorry!The scroller won\'t work for your browser. \n\n I suggest you go get a newer one.')
	}
}

ThreeOhScroll.prototype.getMembers = function() {
	this.container=ypGetElementById('filterContainer');
	this.content=ypGetElementById('filterContent');
	this.thumb=ypGetElementById('filterThumb');
	this.thumbImg=ypGetElementById('filterThumbImg');
	this.thumbContainer=ypGetElementById('filterThumbContainer');
	this.thumbdown=ypGetElementById('down');
	this.thumbup=ypGetElementById('up');
}

ThreeOhScroll.prototype.setDownStyle = function() {
	var obj = this.obj;
	obj.thumbdown.style.cursor="hand";
	obj.thumbdown.style.cursor="pointer";
}

ThreeOhScroll.prototype.setUpStyle = function() {
	var obj = this.obj;
	obj.thumbup.style.cursor="hand";
	obj.thumbup.style.cursor="pointer";
}

var i=0;
var ny=0;
var movetimeout;

ThreeOhScroll.prototype.moveDown= function(){
	var obj = ThreeOhScroll.current;
	if (ny<obj.thumbMax ){
		obj.jumpTo(ny * obj.scrollH / obj.thumbMax)
		ny=ny+5;
		//movetimeout = window.setInterval(obj.moveDown(obj),1000)
		//eval("obj.moveDown(obj)")
	}else{
		obj.jumpTo(obj.thumbMax * obj.scrollH / obj.thumbMax)
		window.clearInterval(movetimeout)
	}	
	//test.innerHTML="scrollH: "+obj.scrollH+"current ny :"+ny+" jumpTo:"+parseInt(ny * obj.scrollH / obj.thumbMax)+" thumbMax:"+obj.thumbMax;
	//test.innerHTML=obj.clipH
}

ThreeOhScroll.prototype.startDown=function(){
	var obj = this.obj;
	ThreeOhScroll.current = this.obj
	if (ny<obj.thumbMax && obj.clipH < obj.content.offsetHeight){
		//obj.jumpTo(ny * obj.scrollH / obj.thumbMax)
		//ny=ny+5;
		movetimeout = window.setInterval(obj.moveDown,100)
		//obj.moveDown(obj);
	}else{
		window.clearTimeout(movetimeout)
	}
	//obj.jumpTo(i)
	//i=i+10;
	//test.innerHTML="current ny :"+ny+" jumpTo:"+parseInt(ny * obj.scrollH / obj.thumbMax)+" thumbMax:"+obj.thumbMax;
	
}

ThreeOhScroll.prototype.stopDown=function(){
	//alert("stop")
	window.clearInterval(movetimeout)
}



ThreeOhScroll.prototype.moveUp= function(){
	var obj = ThreeOhScroll.current;
	if (ny>0){
		obj.jumpTo(ny * obj.scrollH / obj.thumbMax)
		ny=ny-5;
		//ovetimeout = window.setInterval(obj.moveUp(obj),1000)
		//eval("obj.moveDown(obj)")
	}else{
		obj.jumpTo(0 * obj.scrollH / obj.thumbMax)
		window.clearInterval(movetimeout)
	}	
	//test.innerHTML="current ny :"+ny+" jumpTo:"+parseInt(ny * obj.scrollH / obj.thumbMax)+" thumbMax:"+obj.thumbMax;
}

ThreeOhScroll.prototype.startUp=function(){
	var obj = this.obj;
	ThreeOhScroll.current = this.obj
	if (ny>0){
		obj.jumpTo(ny * obj.scrollH / obj.thumbMax)
		ny=ny-5;
		movetimeout = window.setInterval(obj.moveUp,100)
		//obj.moveDown(obj);
	}else{
		window.clearTimeout(movetimeout)
	}
	//obj.jumpTo(i)
	//i=i+10;
	//test.innerHTML="current ny :"+ny+" jumpTo:"+parseInt(ny * obj.scrollH / obj.thumbMax)+" thumbMax:"+obj.thumbMax;
	
}

ThreeOhScroll.prototype.stopUp=function(){
	//alert("stop")
	window.clearInterval(movetimeout)
}






ThreeOhScroll.prototype.startDrag = function(e) {
	if (!e) e = window.event
	var ey = e.pageY ? e.pageY : e.clientY
	this.dragLastY = ey
	this.dragStartOffset = ey - parseInt(this.style.top)
	ThreeOhScroll.current = this.obj
	if ( this.obj.clipH > this.obj.content.offsetHeight) return false;
	document.onmousemove = this.obj.doDrag
	document.onmouseup = this.obj.stopDrag
	if (this.obj.aniTimer) window.clearInterval(this.obj.aniTimer)
	return false;
	
}

ThreeOhScroll.prototype.doDrag = function(e) {
	if (!e) e = window.event
	var obj = ThreeOhScroll.current
	var ey = (e.pageY ? e.pageY : e.clientY)
	var dy = ey - obj.thumb.dragLastY
	ny = parseInt(obj.thumb.style.top) + dy
	if (ny >= obj.thumbMax) obj.thumb.dragLastY = obj.thumbMax + obj.thumb.dragStartOffset
	else if (ny < 0) obj.thumb.dragLastY = obj.thumb.dragStartOffset
	else obj.thumb.dragLastY = ey
	ny = Math.min(Math.max(ny, 0), obj.thumbMax)
	//test.innerHTML= "ny:"+ny+" other:"+parseInt(obj.scrollH / obj.thumbMax)
	obj.jumpTo(ny * obj.scrollH / obj.thumbMax)
	return false;
}

ThreeOhScroll.prototype.stopDrag = function() {
	this.onmousemove = null
	this.onmouseup   = null
}

ThreeOhScroll.prototype.jumpTo = function(ny) {
	this.thumb.style.top	= Math.round(ny * this.thumbMax / this.scrollH)
	this.content.style.top	= -ny
}

function ypGetElementById(id) {
	return (document.getElementById ? document.getElementById(id) : document.all ? document.all[id] : false)
}

function ypGetDescendantsByTagName(sTag, objParent) {
	return (objParent.getElementsByTagName ? objParent.getElementsByTagName(sTag) : objParent.all && objParent.all.tags ? objParent.all.tags(sTag) : false)
}
