﻿var TSRotInt;

var currTS=5;

var maxTS=5;

var TSstatus=1;

var MaxTotRot=(maxTS)+1;

var RotCt=0;

var RotCookie='sbrotckie';

function displayTS(num) {

	for(var count=1; count<=5; count++) {

		if (document.getElementById('story'+count)) {

			if (num==count) { document.getElementById('story'+count).className='tscopy'; }

			else { document.getElementById('story'+count).className='printonly'; }

		}

		if (document.getElementById('tsbtn'+count)) {

			if (count==num) {

document.getElementById('tsbtn'+count).src='/script/images/on'+count+'.gif';

			}

			else {

document.getElementById('tsbtn'+count).src='/script/images/off'+count+'.gif';

			}

		}

	}

	currTS=num;

	if (TSstatus==1) {

		if (TSRotInt) { clearInterval(TSRotInt); }

		if (RotCt<MaxTotRot) { TSRotInt = setInterval('rotateTS()',6000); }

	}

	RotCt++;

}

function rotateTS() {

	if (TSstatus!=1) {

		if (TSRotInt) { clearInterval(TSRotInt); }

		return;

	}

	currTS++; if (currTS>maxTS) { currTS=1; }

	displayTS(currTS);

}

function playpauseTS(newStatus) {

	if (TSstatus==1) {

		TSstatus=0;

		if (TSRotInt) { clearInterval(TSRotInt); }

document.getElementById('tsbtnpp').src='/script/images/play.gif';		

document.getElementById('tsbtnpp').alt='Click to play.';		

		document.cookie = RotCookie + '=n' 

			+ '; expires=".date("D, j M Y",time()+3*31*24*60*60)." 12:00:00 GMT'

			+ '; path=/'

	}

	else {

		TSstatus=1;

		TSRotInt = setInterval('rotateTS()',500);

document.getElementById('tsbtnpp').src='/script/images/pause.gif';		

document.getElementById('tsbtnpp').alt='Click to pause.';

		MaxTotRot=(maxTS*5)+1;

		document.cookie = RotCookie + '=y' 

			+ '; expires=".date("D, j M Y",time()+3*31*24*60*60)." 12:00:00 GMT'



			+ '; path=/'

	}

}


function TSRotFixBtn() {

	if (!document.getElementById('tsbtnpp')) { return; }

	document.getElementById('tsbtnpp').src='/images/play.gif';		

	document.getElementById('tsbtnpp').alt='Click to play.';

}

/*if (readCookie(RotCookie)=='n') {

	TSstatus=0;

	setTimeout('TSRotFixBtn()',2000);

}

else {

	TSRotInt = setInterval('rotateTS()',7500);

}*/