// custom scroll application developed for three.oh 3/2001.
// thanks to brandon (www.jesterworld.net) and grant (no site cuz he's too pimp for it) for the help w/ the visuals.
// > youngpup > www.youngpup.net

// optimized for the latest version of {3.0} by bob

// updated by jonathan brodsky at walltowall design 2006

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"

// this number is for ie4 pc only - which cannot have the description box be of variable width (or atleast i can't figure out how to).
// you set the number of pixels that the desc tag will be permanently.
ThreeOhScroll.ie4pcDescWidth = 100

// i have no idea why this number is necessary, it just is. it is related to how far the scroller is from the top of the window
// in mozilla, but you will have to play with it to get it just right.
ThreeOhScroll.mozAdjust = ThreeOhScroll.mo5 ? 75 : 0

// this is how long it should take the scroller to animate when the user clicks a marker (in milliseconds)
ThreeOhScroll.aniLen = 250


function ThreeOhScroll(id, targetid, height, width, top, offset)
{
	if (ThreeOhScroll.mo5 || (ThreeOhScroll.ie4 && ThreeOhScroll.pc) || ThreeOhScroll.ie5) {
		
		var objTarget = document.getElementById(targetid)
		var contents = objTarget.innerHTML
		objTarget.innerHTML = beforeTags(id, height, width, top, offset) + contents + afterTags(id);
		
		this.id = id
		this.getMembers()
		if (ThreeOhScroll.ie4 && !ThreeOhScroll.ie5 && ThreeOhScroll.pc) this.description.style.width = ThreeOhScroll.ie4pcDescWidth
		
		this.clipH		= parseInt(this.container.style.height)
		this.PTags		= ypGetDescendantsByTagName("P", 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.thumb.onmousedown = this.startDrag
	} else {
		// alert ('ha ha!\n\nThe ThreeOh scroller won\'t work for your browser. Don\'t you feel stupid??\n\n I suggest you go get a newer one.')
	}
}

ThreeOhScroll.prototype.getMembers = function() {		
	this.container=ypGetElementById(this.id + 'Container');
	this.content=ypGetElementById(this.id + 'Content');
	this.thumb=ypGetElementById(this.id + 'Thumb');
	this.thumbImg=ypGetElementById(this.id + 'ThumbImg');
	this.thumbContainer=ypGetElementById(this.id + 'ThumbContainer');
}

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
	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
	var 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)
	obj.jumpTo(ny * obj.scrollH / obj.thumbMax)
	return false;
}

ThreeOhScroll.prototype.stopDrag = function() {
	this.onmousemove = null
	this.onmouseup   = null
}

ThreeOhScroll.prototype.scrollTo = function(ny) {
	this.endArrow = Math.round(ny * this.markersMax / this.scrollH)
	this.startTime = (new Date()).getTime()
	this.startPos = parseInt(this.content.style.top) * -1
	this.endPos = ny
	this.dist = this.endPos - this.startPos
	this.accel = this.dist / ThreeOhScroll.aniLen / ThreeOhScroll.aniLen
	if (this.aniTimer) this.aniTimer = window.clearInterval(this.aniTimer)
	this.aniTimer = window.setInterval(this.gRef + ".scroll()", 10)
}

ThreeOhScroll.prototype.scroll = function() {
	var now = (new Date()).getTime()
	var elapsed = now - this.startTime
	if (elapsed > ThreeOhScroll.aniLen) this.endScroll()
	else {
		var t = ThreeOhScroll.aniLen - elapsed
		var ny = this.endPos - t * t * this.accel
		this.jumpTo(ny)
	}
}

ThreeOhScroll.prototype.endScroll = function() {
	this.jumpTo(this.endPos)
	this.arrow.style.top = this.endArrow
	this.aniTimer = window.clearInterval(this.aniTimer)
}

ThreeOhScroll.prototype.jumpTo = function(ny) {
	this.thumb.style.top	= Math.round(ny * this.thumbMax / this.scrollH)
	this.content.style.top	= -ny
}

function ypGetChildNodes(objParent) {
	return (objParent.childNodes ? objParent.childNodes : objParent.children)
}

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)
}

var gIncrement = 15;
var gTimerId = null;

ThreeOhScroll.prototype.scrollDn = function() {
	gTimerId = window.setInterval(this.gRef + ".increment(false)", 25);
}

ThreeOhScroll.prototype.scrollUp = function() {
	gTimerId = window.setInterval(this.gRef + ".increment(true)", 25);
}

ThreeOhScroll.prototype.stopScroll = function() {
	window.clearInterval(gTimerId);
}

ThreeOhScroll.prototype.increment = function(bUp) {
	var iNext = -parseInt(this.content.style.top) + (bUp ? -gIncrement : gIncrement);
	if (iNext <= this.scrollH && iNext >= 0) {
		this.jumpTo(iNext);
	} else if (iNext > this.scrollH) {
		window.clearInterval(gTimerId);
		this.jumpTo(this.scrollH);
	} else {
		window.clearInterval(gTimerId);
		this.jumpTo(0);
	}
}
function beforeTags(id, height, width, top, offset){
	return '<div style="position: absolute; left: 0px; top:' + (top) + 'px; width:' + width + 'px; height:' + height + 'px;" id="' + id + '"><div style="position: absolute; left: 13px; top:' + (top + 1) + 'px; width: 9px; height: ' + (height-1) + 'px;" id="' + id + 'ScrollBar"><div style="background:#a8a69D;position: absolute; left: ' + (width - 6) + 'px; width: 10px; height: ' + (height-offset) + 'px;" id="' + id + 'ThumbContainer"><div style="position: absolute; top:' + (top) + 'px; cursor: pointer; background-color: rgb(219, 215, 202);" id="' + id + 'Thumb"><div style="position: absolute; top:' + (top + 1) + 'px; cursor: pointer; background-color: rgb(209, 74, 0);" id="' + id + 'ThumbInternals"></div><img src="/imgs/thumb.gif" id="' + id + 'ThumbImg" height="10" width="10"></div></div></div><div style="overflow:hidden; position: absolute; width:' + (width + 3) + 'px; height: ' + (height-1) + 'px; clip: rect(0pt, ' + (width + 6) + 'px, ' + (height-1) + 'px, 0pt);" id="' + id + 'Container"><div style="position: absolute; top:' + (top) + ';padding-right:20px;" id="' + id + 'Content">';
}
function afterTags(){
	return '</div></div></div>';
}
function arrowButtonsWrite(left){
	if(left == null){
		left = "347";
	}
	document.write('<img onmouseup="f.increment(true);" onclick="return false;" style="position: absolute; top: 145px; left: '+ left +'px; z-index: 300; cursor: pointer;" src="/imgs/scroll_up_arrow.gif" height="10" width="10"><img onmouseup="f.increment(false);" onclick="return true;" style="position: absolute; top: 433px; left: '+ left +'px; z-index:10; cursor: pointer;" src="/imgs/scroll_down_arrow.gif" height="10" width="10" id="scroller_down_arrow">');
}