
function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 230" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 230; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}


function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("cont").getElementsByTagName("DIV");
		if(el.style.display == "none"){
			for (var i=0; i<ar.length; i++){
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
function ChangeClass(menu, newClass) { 
	 if (document.getElementById) { 
	 	document.getElementById(menu).className = newClass;
	 } 
} 
document.onselectstart = new Function("return true");

function filter(imagename,objectsrc){
if (document.images)
document.images[imagename].src=eval(objectsrc+".src")
}

a1=new Image(19,20)
a1.src="images/mpyou.jpg"
a2=new Image(19,20)
a2.src="images/mpyhover.jpg"
b1=new Image(19,20)
b1.src="images/aikb.jpg"
b2=new Image(19,20)
b2.src="images/aikbhover.jpg"
c1=new Image(19,20)
c1.src="images/jinkei.jpg"
c2=new Image(19,20)
c2.src="images/jinkeihover.jpg"
d1=new Image(19,20)
d1.src="images/incharge.jpg"
d2=new Image(19,20)
d2.src="images/inchargehover.jpg"

// Content scroller
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)
{
	if (ThreeOhScroll.mo5 || (ThreeOhScroll.ie4 && ThreeOhScroll.pc) || ThreeOhScroll.ie5) {
		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.markersMax	= parseInt(this.markers.style.height) - 7
		this.thumbMax	= parseInt(this.thumbContainer.style.height) - this.thumbImg.height
		this.arrowMax	= parseInt(this.arrowContainer.style.height) - this.arrowImg.height
		
		this.gRef = "ThreeOhScroll_"+id
		eval(this.gRef+"=this")
		this.thumb.obj	= this
		this.thumb.onmousedown = this.startDrag
		this.thumb.onmouseover = Function(this.gRef + ".toggleThumb(1)")
		this.thumb.onmouseout  = Function(this.gRef + ".toggleThumb(0)")
		this.thumb.onmouseup   = Function(this.gRef + ".toggleThumb(0)")
		this.thumb.ondragstart = function() { return false }
		this.initMarkers()
	} 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.initMarkers = function() {
	var shtml = "", sTitle, iTop
	for (var i = 0; i < this.PTags.length; i++) {
		sTitle	= this.PTags[i].getAttribute("description")
		pTop	= this.PTags[i].offsetTop - ThreeOhScroll.mozAdjust
		iTop	= Math.round(pTop * this.markersMax / this.scrollH)
		if (sTitle && sTitle != "" && sTitle != null) {
			shtml  += "<div id='" + this.id + "_marker_" + i + "' "
			shtml  += "style='position:absolute; left:2px; top:" + (iTop + 2) + "px; "
			shtml  += "width:5px; height:3px; clip:rect(0 5 3 0); background-color:#05aa01; z-index:3;'></div>"
			shtml  += "<div style='position:absolute; left:0px; top:" + iTop + "px; "
			shtml  += "cursor:pointer; cursor:hand; width:9px; height:7px; clip:rect(0 9 7 0); z-index:4;' " 
			shtml  += "onmousedown='" + this.gRef + ".scrollTo(" + pTop + ")' "
			shtml  += "onmouseover='" + this.gRef + ".toggleMarker(this, " + i + ", 1)' "
			shtml  += "onmouseout='" + this.gRef + ".toggleMarker(this, " + i + ", 0)' "
			shtml  += "description='" + sTitle.replace(/'/g, "|pos|") + "'>"
			shtml  += "<img src='x.gif' width='9' height='7'></div>"
		}
	}
	this.markers.innerHTML += shtml
}

ThreeOhScroll.prototype.getMembers = function() {
	this.container=ypGetElementById('filterContainer');
	this.content=ypGetElementById('filterContent');
	this.markers=ypGetElementById('filterMarkers');
	this.thumb=ypGetElementById('filterThumb');
	this.arrow=ypGetElementById('filterArrow');
	this.thumbImg=ypGetElementById('filterThumbImg');
	this.arrowImg=ypGetElementById('filterArrowImg');
	this.thumbContainer=ypGetElementById('filterThumbContainer');
	this.arrowContainer=ypGetElementById('filterArrowContainer');
	this.description=ypGetElementById('filterDescription');
	this.descArrow=ypGetElementById('filterDescArrow');
}

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.current.toggleThumb(0)
}

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.arrow.style.top	= Math.round(ny * this.arrowMax / this.scrollH)
	this.content.style.top	= -ny
}

ThreeOhScroll.prototype.toggleMarker = function(oTrigger, markerNum, bOn) {
	if (bOn) {
		ypGetElementById(this.id + "_marker_" + markerNum).style.backgroundColor = "#444444"
		if (this.curMarker) this.toggleMarker(this.curMarker, 0)
		this.curMarker = markerNum
		this.descArrow.style.top = parseInt(oTrigger.style.top) + 2 + "px"
		this.description.style.left = "-400px"
		this.description.style.top = "-400px"
		this.description.innerHTML = oTrigger.getAttribute("description")
		var w = document.all && !ThreeOhScroll.ie5 ? ThreeOhScroll.ie4pcDescWidth : this.description.offsetWidth
		this.description.style.left = 259 - w + "px"
		this.description.style.top = parseInt(oTrigger.style.top) - 1 + "px"
		this.description.style.visibility = "visible"
		this.descArrow.style.visibility = "visible"
		this.container.style.left = "0px"
	} else {
		ypGetElementById(this.id + "_marker_" + markerNum).style.backgroundColor = "#cccccc"
		this.curMarker = 0
		this.description.style.visibility = "hidden"
		this.descArrow.style.visibility = "hidden"
	}
}

ThreeOhScroll.prototype.toggleThumb = function(bOn) {
	//this.arrow.style.backgroundColor = this.thumb.style.backgroundColor = bOn ? "#7CDAFE" : "#5EBBE7"
}

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