/* The Amazing ASSTR Onan-O-Matic Autoscroller! 
 * Original by BitBard with revisions by
 * "Michael the ASSTR Guy" (code@asstr.org), 
 * Revised and commented by Vinnie Tesla (vinnie_tesla@yahoo.com) January 2003 
 *
 * THIS CODE IS HEREBY PLACED INTO THE PUBLIC DOMAIN, authorized for any use
 * by any person or entity for any purpose.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See http://www.scrollscreen.com/terms.html for more details.
 */

/* This is the first time I've ever written code for someone else to use.
 * Please feel free to contact me with your questions/comments/criticisms.
 *			--Vinnie
 */

if (window != window.top) {top.location.href = location.href;}

var y=0;
var lasty=0;
var uagent=navigator.userAgent;
var hop = 0;
var aieee=0;
var scratch;
var workInterval = 0;
var scrollInterval = -2;
var cruft = 0

/* The following, as well as much other code, was mooched from
 * "Making You Webpage Compatable with Mozilla" by Nicolás Lichtmaier
 * http://mazinger.technisys.com.ar/pruebas-nick/mozilla/docs/compat.html
 * an excellent guide to curing IE-proprietary Javascript. This bit teaches
 * IE 5 how to deal with the DOM getElementById method
 */
if(!document.getElementById && document.all)
	document.getElementById = function(id)
	{
		return document.all[id];
	}


if ((uagent.indexOf("MSIE") > 0) && (uagent.indexOf("Mac")) < 0) {
	aieee = 1;
}

/* document.layers was Netscape 4's alternative to the DOM. I don't 
 * understand it, so all "if (cruft)" code is just pasted from Mike's version.
 */
if (document.layers) {
	cruft = 1
}

function getScrollRate(){
	if (cruft) {
		return document.layers[0].document.speedy.ss.options[document.layers[0].document.speedy.ss.selectedIndex].value;
	} else {
		return document.getElementById("speedy").ss.options[document.getElementById("speedy").ss.selectedIndex].value;
	}
}

function about_scroller(){
	if (cruft) {
	   document.layers[0].document.speedy.ss.options[0].selected=1;
	   startRemote( 'http://www.scrollscreen.com/info/static/scroller_netscape.html' );
	}  else {
	   document.getElementById("speedy").ss.options[0].selected=1;
	   startRemote( 'http://www.scrollscreen.com/info/static/scroller_ie.html' );
	}
}

function scroller() {
	if (cruft) {
	   y = getY() + 3;
	} else {		
	   y = getY() + 1;
	}
	top.scroll(0,y);
	if (aieee || cruft) {
		holdwork();
	}
	return true;
}

function setfontsize(fs) {
	scratch=fs+"pt";	
	if (cruft) {
	       document.tags.P.fontSize=scratch;
	} else {
    		document.body.style.fontSize=scratch;
	}
}

/* This function actually creates the scrollbar. 
 * The first bit is fun: the CSS position:fixed attribute fixes an element
 * relative to the browser window instead of the document. It's been 
 * around since 1998, but IE hasn't seen fit to implement it yet. 
 * hold() and holdwork() are the workarounds to fake a similar effect
 * by repositioning the control bar once a second. Yuk.
 */
function runScroller() {
	if (aieee) {
		document.writeln( '<DIV ID="floatScroll" style="position:absolute; left: 0; top:0;">' );
	} else {
		if (cruft) {
 			document.writeln( '<LAYER name="floatScroll">' );  
		}
		else {
			 document.writeln( '<DIV ID="floatScroll" style="position: fixed; left: 0; top:0;">' );
		}
	}
	document.writeln('<table border=0>');
	document.writeln('<tr><td>');
	document.writeln('<FORM name="speedy" id="speedy">');
	document.writeln('<select name="ss" id="ss" onChange="unpause();" onFocus="dopause();"');


	document.writeln('<option value="1">Scroll Very Fast');
	document.writeln('<option value="3">Fast Scroll');
	document.writeln('<option value="10">Medium Scroll');
	document.writeln('<option value="25">Slow Scroll');
	document.writeln('</select>');
	/*if (!cruft) {
		document.writeln('<select name="fs" id="fs" onChange="setfontsize(this.options[this.selectedIndex].value); return true;">');
		document.writeln('<option value="8">Font Size 8');
		document.writeln('<option value="9" selected>Font Size 9');
		document.writeln('<option value="10">Font Size 10');
		document.writeln('<option value="11">Font Size 11');
		document.writeln('<option value="12">Font Size 12');
		document.writeln('<option Selected value="13">Font Size 13');
		document.writeln('<option value="14">Font Size 14');
		document.writeln('<option value="15">Font Size 15');
		document.writeln('<option value="20">Font Size 20');
		document.writeln('<option value="25">Font Size 25');
		document.writeln('<option value="30">Font Size 30');
		document.writeln('</Select>');
		document.getElementById("speedy").fs.options[5].selected=1;
	}*/

	document.writeln('<input type=button id="pause" name=pause value=Start onclick=parent.pause()>');
	document.writeln('<input type=button id="hide" name=hide value=Hide onclick=parent.hide()>');
	//document.writeln('<input type=submit id="textonly" name=textonly value="Text Only">');
	// document.writeln('<input type=submit id="textonly" name=textonly value="Text Only" onclick=submit();>');
	document.writeln('</FORM>');
	document.writeln('</td><td>');
	//document.writeln('<FORM method=post action=' + location.href + '.prc?rw=T>');
	//document.writeln('<input type=submit id=palm value="Palm Format" onclick=submit();>');
	//document.writeln('</FORM>');
	document.writeln('</td><td>');
	//document.writeln('<FORM method=post action=http://www1.asstr.org/cgi-bin/prandom.pl>');
	//document.writeln('<input type=submit id=random value="Random Story" onclick=submit();>');
	//document.writeln('</FORM>');
	document.writeln('</td>');
	document.writeln('</table>');
	document.writeln('<br>');
	if (cruft) {
		document.writeln( '</LAYER>' );
	} else {
		document.writeln( '</DIV>' );
	}
	document.writeln( '<br><br>' );
	if (cruft) {
		document.layers[0].document.speedy.ss.options[0].selectedIndex=3;
	} else {
		document.getElementById("speedy").ss.options[0].selectedIndex=3;
		document.getElementById("speedy").ss.options[1].selectedIndex=1;
	}
	if (aieee || cruft) {
		hold();
	}
	return true;
}

function getY(){
	if (cruft) {
		return top.pageYOffset;
	} else {
		return document.body.scrollTop;
	}
}

function holdwork(){
	if (cruft) {
		obj = document.floatScroll;
	} else {
		obj = document.getElementById("floatScroll").style;
	}
	obj.top = getY();
}

function hold(){
	holdwork();
	workInterval = setInterval( "holdwork()", 1000 );
}

function hide(){
	if (cruft) {
		document.floatScroll.visibility = "hide";
	} else {	
		document.getElementById("floatScroll").style.visibility = "hidden";
	}
	clearInterval( workInterval );
	return false;
}

function pause(){
	if( getScrollRate() == 0 ){
		return;
	}
	if( hop == 0 ){
		unpause();
	} else {
		dopause();
	}
	return true;
}

function dopause(){
	if( scrollInterval != -2 ){
		clearInterval( scrollInterval );
	}
	hop = 0;
	if (cruft) {
		document.layers[0].document.speedy.pause.value = "Start";
	} else {
		document.getElementById("pause").value = "Start";
	}
}

function unpause(){
	if( scrollInterval != -2 ){
		clearInterval( scrollInterval );
	}
	hop = 1;
	if (cruft) {
		document.layers[0].document.speedy.pause.value = "Stop";
	} else {
		document.getElementById("pause").value = "Stop";
	}
	if( getScrollRate() != 999 ){
		scrollInterval = setInterval( "scroller()", getScrollRate() );
	} else {
		about_scroller();
	}
}




