// Script: TopicSwap Functions   Version: 1.0   Version Date: 6/1/2001
// Originator: Ronald E. Grafe     Email: rgrafe@texas.net
// Website: http://www.lonestar.texas.net/~rgrafe/
// This script can be freely distributed and modified as long as this section
// is included in the code.

<!-- Browser check -->

var isNav=document.layers?1:0
var isIE=document.all?1:0
var isNav6=document.getElementById&&!document.all?1:0

<!-- global variables for functions -->
var pos=1
var count = 0
var heightcounter = 0
var scrolltimerup
var scrolltimerdown
var opentimer
var scrolldownon="no"
var scrollupon="no"
var swappertimeron="no"
var firstloop=1
var viewcounter = 250
var viewwidth = 0
var viewcounterp = 250
var viewwidthp = 0
var obj = ""
var contentobj = ""
var speed = 50
var stepdown = -1
var stepup = 1
var stepdownn6 = 0
var stepupn6 = 0

// Sets objects according to browser after loading page
function setobjects() {
	if (isNav6) {
       obj = document.getElementById("text").style
	   contentobj = document.getElementById("text")
	   stepdownn6=-1
	   stepupn6=1
	} else if (isIE) {
       obj = eval("document.all.text.style")
	   contentobj = eval("document.all.text")
	} else {
	   obj = document.layers[1].document.layers[0]
	} 
	typetext(1)
}

<!-- loads the topic content from the textArray into the text DIV tag -->
function typetext(incoming) {
	heightcounter = 0
	pos=incoming
	if (isNav6) {
	   contentobj.innerHTML = ""
	   contentobj.innerHTML=textarray[pos]
	} else if (isIE) {
	   contentobj.innerHTML = ""
	   contentobj.insertAdjacentHTML("BeforeEnd","<font type='times' size='1' style='color:white;font-weight:normal'>"+textarray[pos]+"</font>")
	} else {
	   document.textcontainerns.document.textns.document.write("<layer>"+textarray[pos]+"</layer>")
	   document.textcontainerns.document.textns.document.close()
	} 
	   shiftto(0,0)
	   counterchg()
	   count=pos
}

<!-- increments or decrements the counter in the counter DIV tag -->
function counterchg() {
	if (isNav6) {
       var objc = document.getElementById("counter").style
	   var contentobjc = document.getElementById("counter")
	   contentobjc.innerHTML = ""
	   //contentobjc.innerHTML="<font type='times' size='1' style='color:white;font-weight:bold;'>"+pos+" of "+(textarray.length-1)+"</font>"
	} else if (isIE) {
       var objc = eval("document.all.counter.style")
	   var contentobjc = eval("document.all.counter")
	   contentobjc.innerHTML = ""
	   //contentobjc.insertAdjacentHTML("BeforeEnd","<font type='times' size='1' style='color:white;font-weight:bold'>"+pos+" of "+(textarray.length-1)+"</font>")
	} else {
	   document.countercontainerns.document.counterns.document.write("<layer><font type='times' size='1' style='color:white;font-weight:bold;text-align:center;'>"+pos+" of "+(textarray.length-1)+"</font></layer>")	   	   
	   document.countercontainerns.document.counterns.document.close()
	}
}

<!-- scroll function for scrolling down through a topic -->
function scrolldown() {
stopall()
var objheight = getobjectheight()
	if(heightcounter<objheight) {
		shiftby(0,stepdown+stepdownn6)
		heightcounter = heightcounter + 1
		scrolldownon = "yes"
		scrolltimerdown = setTimeout("scrolldown()",speed)
	}else{
		stopall()
		scrollup()
		scrolldownon = "no"
		scrollupon = "yes"
	}
}

<!-- scroll function for scrolling up through a topic -->
function scrollup() {
stopall()
	if (heightcounter>=0) {
		shiftby(0,stepup+stepupn6)
		heightcounter = heightcounter - 1
		scrollupon = "yes"
		scrolltimerup = setTimeout("scrollup()",speed)
	}else{
		stopall()
		scrolldown()
		scrollupon = "no"
		scrolldownon = "yes"
	}
}

<!-- swapper timer function for switching topics -->
function swapper() {
	heightcounter = 0
	if(pos<textarray.length-1) {
		pos=pos+1
		openview()
		typetext(pos)
	}else{
		pos=1
		openview()
		typetext(pos)
	}
	swappertimeron = "yes"
	swappertimer=setTimeout("swapper()",6000)
}

<!-- selects the textArray[ ] content for the next topic, or the topic manually selected by the user. -->
function nexttext(man) {
	stopall()
	heightcounter = 0
	if (man) {
		openview()
		typetext(man)
	}else{
		if (count == (textarray.length-1)) {
			count = 1
		}else{
			count = count+1
		}
		openview()
		typetext(count)
	}
}

<!-- selects the content from the previous topic in the textArray[ ]. -->
function prevtext() {
	stopall()
	heightcounter = 0
	if (count > 1) {
		count = count-1
	}else{
		count=textarray.length-1
	}
	openviewp()
	typetext(count)
}

<!-- Wipe control for moving to the next topic. -->
function openview() {	
	if (isNav6) {
       var obj = document.getElementById("textcontainer").style
	} else if (isIE) {
       var obj = eval("document.all.textcontainer.style")
	} else {
	   var obj = document.textcontainerns
	}
	if(viewcounter >=0) {
		if(isNav) {
			obj.clip.right = viewwidth
			}
		if(isIE) {
			obj.clip="rect(0 "+viewwidth+" 100 0)"
			}
		viewcounter--
		viewwidth = viewwidth+5
		opentimer = setTimeout("openview()",1);	
	}else{
		clearTimeout(opentimer)
		viewcounter = 250
		viewwidth = 0
	}
}


<!-- Wipe control for moving to the previous topic. -->
function openviewp() {	
	if (isNav6) {
       var obj = document.getElementById("textcontainer").style
	} else if (isIE) {
       var obj = eval("document.all.textcontainer.style")
	} else {
	   var obj = document.textcontainerns
	}
	if(viewcounterp >=0) {	
		if(isNav) {
			obj.clip.left = viewwidthp
			}
		if(isIE) {
			obj.clip="rect(0 250 100 "+viewwidthp+")"
			}
		viewcounterp--
		viewwidthp = viewwidthp-2
		opentimer = setTimeout("openviewp()",1);	
	}else{
		clearTimeout(opentimer)
		viewcounterp = 250
		viewwidthp = 250
	}
}

<!-- function that shifts the object to top -->
function shifttotop() {
	shiftto(0,0)
	stopall()
	heightCounter = 0
}

<!-- Positioning an object at a specific pixel coordinate -->
function shiftto(x, y) {
	if (isNav) {
		obj.moveTo(x,y)
	} else if (isNav6) {
		obj.left = x
		obj.top = y
	} else {
		obj.pixelLeft = x
		obj.pixelTop = y
	}
}

<!-- Moving an object by x and/or y pixels -->
function shiftby(deltaX, deltaY) {
	if (isNav) {
		obj.moveBy(deltaX, deltaY)
	} else if (isNav6) {
		obj.left = parseInt(obj.left) + deltaX
		obj.top = parseInt(obj.top) + deltaY
	} else {
		obj.pixelLeft += deltaX
		obj.pixelTop += deltaY
	}
}

<!-- Gets object height in pixels -->
function getobjectheight() {
	if(isNav) {
		return obj.clip.height
	}else if(isNav6) {
		return contentobj.offsetHeight
	}else{
		return contentobj.clientHeight
	}
}

<!-- function to stop running timers -->
function stopall() {
	if(scrolldownon=="yes") {
	clearTimeout(scrolltimerdown)
	scrolldownon = "no"
	}
	if(scrollupon=="yes") {
	clearTimeout(scrolltimerup)
	scrollupon = "no"
	}
	if(swappertimeron=="yes") {
	clearTimeout(swappertimer)
	swappertimeron = "no"
	}
}

