var divName = "scrollDiv"; // name of main div that shows the scrolling
var tmpName = "tempDiv"; // name of temporary div (inner div for scrolling)
var scrollDir = "up"; // direction that text scrolls - up or down
var speedControl =  85; // update interval in milliseconds
//////////////// do not touch below ///////////////////
// differences between IE and NS:
// IE considers: top: 0px; left: 0px; is top left of the div frame
// NS considers: top: 0px; left: 0px; is top left of the entire page
/*
Here's the rough flow.  This code duplicates content into two different divs.
*/
var scrollFlag = "yes"; // flag that is used to pause when mouseover
// to stop the page, set flag to something other than "yes"
var theDivPos = 0; // this is a number used for y-positioning of first div
// it dictates the div's position relative to parent div
// e.g. 0 means top of parent div, NOT top of page
var tmpDivPos = 0; // this is a number used for y-positioning of second div
// it dictates the div's position relative to parent div
// e.g. 0 means top of parent div, NOT top of page
var scrollDivHeight = 0;
var negDivHeight = 0; // negative number of scollDivHeight
var theDivTopPos = 0; // div's position relative to entire page
var tmpDivTopPos = 0; // div's position relative to entire page
function scroll_setup(divContent) {
eval
var theDivObj = document.getElementById(divName); // initialize obj
var tmpDivObj = document.getElementById(tmpName); // initialize obj
//alert('debug scroll_div.js--- input='+divContent);
theDivObj.innerHTML = divContent; // write the content into the main div
tmpDivObj.innerHTML = divContent; // write the content into the secondary div
scrollDivHeight = theDivObj.offsetHeight; // gets height of the obj
negDivHeight = 0 - scrollDivHeight;
// begin positioning the temp div so it is underneath the main div
if (IE_style == "yes") {
tmpDivObj.style.top = scrollDivHeight; // position the temp div below the main div
} else {
var returnArr = findPos(theDivObj); // returns an arr of [0] = left, [1] = top
theDivTopPos = returnArr[1];
tmpDivTopPos = theDivTopPos+scrollDivHeight;
tmpDivObj.style.top = tmpDivTopPos; // position the temp div below the main div
}
tmpDivPos = scrollDivHeight;
// end positioning the temp div so it is underneath the main div
checkScroll();
}
// debug
var rec_step=0;
function checkScroll() {
// use this function because it prevents user from moving mouse
// too fast and calling scrollFunction to over-activate and speed up
if (scrollFlag == "yes") {
scrollFunction();
}
setTimeout("checkScroll()", speedControl);
// debug
//alert('debug scroll_div.js--- recursive step='+rec_step);
//rec_step++;
}
function scrollFunction() {
if (scrollDir == "up") {
theDivPos -= 1; // pull the div 1 px up
tmpDivPos -= 1; // pull the div 1 px up
} else {
theDivPos += 1; // pull the div 1 px up
tmpDivPos += 1; // pull the div 1 px up
}
if (IE_style == "yes") { // for IE
document.getElementById(divName).style.top = theDivPos;
document.getElementById(tmpName).style.top = tmpDivPos;
} else { // for non-IE
document.getElementById(divName).style.top = theDivTopPos+theDivPos;
document.getElementById(tmpName).style.top = theDivTopPos+tmpDivPos;
}
if (scrollDir == "up") {
if (theDivPos <= negDivHeight) {
theDivPos = scrollDivHeight;
if (IE_style == "yes") {
document.getElementById(divName).style.top = theDivPos;
} else {
document.getElementById(divName).style.top = theDivTopPos+theDivPos;
}
}
if (tmpDivPos <= negDivHeight) {
tmpDivPos = scrollDivHeight;
if (IE_style == "yes") {
document.getElementById(tmpName).style.top = tmpDivPos;
} else {
document.getElementById(tmpName).style.top = theDivTopPos+tmpDivPos;
}
}
} else { // scrollDir != "up"
if (theDivPos >= scrollDivHeight) {
theDivPos = negDivHeight;
if (IE_style == "yes") {
document.getElementById(divName).style.top = theDivPos;
} else {
document.getElementById(divName).style.top = theDivTopPos+theDivPos;
}
}
if (tmpDivPos >= scrollDivHeight) {
tmpDivPos = negDivHeight;
if (IE_style == "yes") {
document.getElementById(tmpName).style.top = tmpDivPos;
} else {
document.getElementById(tmpName).style.top = theDivTopPos+tmpDivPos;
}
}
}
}
function findPos(obj) {
// find the position of the div with respect to the page
// returns an array
//   [0] = pixels from left
//   [1] = pixels from top
var curleft = curtop = 0;
if (obj.offsetParent) { // offsetParent is built in
curleft = obj.offsetLeft;
curtop = obj.offsetTop;
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}
