//Credit: Information Technology Group http://itg.indiana.edu Chemitg@indiana.edu
//Share any updates/changes made to this code with Information Technology Group, Department of Chemistry, Indiana University Bloomington

var timeout = 3 * 1000; // in milliseconds

var tt_speed = 1;
var tt_speedRef = 1;

var HANDLEtimer;
var HANDLEinterval;

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=500,height=500');");
}

function tick_tock2() {
	tape.style.top = parseInt(tape.style.top) - tt_speed + "px";
	tape2.style.top = parseInt(tape2.style.top) - tt_speed + "px";
	
	if(tt_speed > 0){
		if(parseInt(tape.style.top) < actualHeight*(-1)){
			tape.style.top = parseInt(tape2.style.top) + actualHeight2 + "px";
		}
		if(parseInt(tape2.style.top) < actualHeight2*(-1)){
			tape2.style.top = parseInt(tape.style.top) + actualHeight + "px";
			if(tt_speed == 1){
				stopTicker();
			}
		}
	}else if(tt_speed < 0){
		if(parseInt(tape.style.top) > actualHeight2){
			tape.style.top = parseInt(tape2.style.top) - actualHeight + "px";
		}
		if(parseInt(tape2.style.top) > actualHeight){
			tape2.style.top = parseInt(tape.style.top) - actualHeight2 + "px";
		}
	}
}

function stopTicker(){
	clearInterval(HANDLEinterval);
	HANDLEtimer = setTimeout('startTicker()', timeout);
}

function startTicker(){
	clearTimeout(HANDLEtimer);
	HANDLEinterval = setInterval("tick_tock2()",60);
}

function initTicker() {
	tape = document.getElementById("scroll");
	tape2 = document.getElementById("scroll2");
	actualHeight = tape.offsetHeight;
	actualHeight2 = tape2.offsetHeight;
	tape.style.top = "0";
	tape2.style.top = parseInt(tape.style.top) + actualHeight + "px";	
	stopTicker();
}

if (window.addEventListener) {
	window.addEventListener("load", initTicker, false);
} else {
	if (window.attachEvent) {
		window.attachEvent("onload", initTicker);
	} else {
		if (document.getElementById) {
			window.onload = initTicker;
		}
	}
}