// These variables control the duration and speed of the scrolling quotes
//
var timeBetweenScrolls = 4;
var scrollingSpeed = 1;

function openit(sURL){
//newwindow=open(sURL,"icons","toolbar=yes,directories=no,menubar=yes,resizable=yes,status=yes,fullscreen=no, scrollbars=auto");
newwindow=open(sURL,"icons","toolbar=no,directories=no,menubar=no,resizable=no,status=no,fullscreen=no, scrollbars=auto");}
// The ScrollingGroup object represents a group of one or more quotes that needs to be scrolled
// into or out of view.  Once attached to the group's <div> tag, this object can be used to scroll
// quotes into or out of view.
function ScrollingGroup( id )
{
this.id = id;
this.nextQuoteId = 0;
this.yPos = this.getDocumentHeight();
this.scrollingComplete = false;
}
ScrollingGroup.SCROLL_INTO_VIEW = 1;
ScrollingGroup.SCROLL_OUT_OF_VIEW = 0;

// Scroll the group into view
function ScrollingGroup_scrollUp( which ) {
	if ( !this.scrollingComplete ) {
		this.yPos -= scrollingSpeed;
		var element = document.getElementById( this.id );
		element.style.top = this.yPos + "px";

		// Based on whether we're scrolling into or out of view, stop scrolling when we need to
		if ( which == ScrollingGroup.SCROLL_OUT_OF_VIEW ) {
			if ( element.offsetHeight - Math.abs( this.yPos ) <= 0 ) {
				element.style.visibility = "hidden";
				this.yPos = this.getDocumentHeight();
				element.style.top = this.yPos + "px";
				this.scrollingComplete = true;
				}
			}
		else {
			if ( this.yPos <= 0 ) {
				this.yPos = 0;
				element.style.top = "0px";
				this.scrollingComplete = true;
				}
			}
		}
}
ScrollingGroup.prototype.scrollUp = ScrollingGroup_scrollUp;

// Determine if the scrolling is done
function ScrollingGroup_doneScrolling()
{
return this.scrollingComplete;
}
ScrollingGroup.prototype.doneScrolling = ScrollingGroup_doneScrolling;

// Set the y-position
function ScrollingGroup_setVerticalOffset( yPos )
{
this.yPos = yPos;
var element = document.getElementById( this.id );
element.style.top = yPos + "px";
}
ScrollingGroup.prototype.setVerticalOffset = ScrollingGroup_setVerticalOffset;

// Make the quote visible
function ScrollingGroup_show()
{
var element = document.getElementById( this.id );
element.style.visibility = "visible";
}
ScrollingGroup.prototype.show = ScrollingGroup_show;


// Set the next quote in line after this quote

function ScrollingGroup_setNextQuote( id )

{
this.nextQuoteId = id;
}
ScrollingGroup.prototype.setNextQuote = ScrollingGroup_setNextQuote;

// Get the next quote in line after this quote
function ScrollingGroup_getNextQuote()
{
return this.nextQuoteId;
}
ScrollingGroup.prototype.getNextQuote = ScrollingGroup_getNextQuote;

// Get the height of the document (since this is different for IE and Mozilla)
function ScrollingGroup_getDocumentHeight()
{
if ( window.innerHeight )
{
return window.innerHeight;
}
else
{
return document.body.offsetHeight;
}
}
ScrollingGroup.prototype.getDocumentHeight = ScrollingGroup_getDocumentHeight;

// These are the current and next quote groups
var currentQuote = null;
var nextQuote = null;

// Initialize the scrolling
function initializeScrolling()
{
// For each <div> on the page, associate it with a ScrollingGroup object
var divElements = document.getElementsByTagName( "DIV" );
var previousGroup = null;
for ( var index = 0; index < divElements.length; index++ )
{
var group = new ScrollingGroup( divElements[ index ].id );
divElements[ index ].jsObject = group;

if ( previousGroup != null )
{
previousGroup.setNextQuote( divElements[ index ].id );
}
previousGroup = group;
}
previousGroup.setNextQuote( divElements[ 0 ].id );

// Make the first quote visible
divElements[ 0 ].jsObject.setVerticalOffset( 0 );
divElements[ 0 ].jsObject.show();

currentQuote = divElements[ 0 ].jsObject;
nextQuote = divElements[ 1 ].jsObject;
nextQuote.show();
nextQuote.setVerticalOffset( divElements[ 0 ].offsetHeight + 20 );
window.setTimeout( "scrollQuotes();", timeBetweenScrolls * 1000 );
}


// Scroll the quotes
function scrollQuotes()
{
var allScrollingComplete = true;

if ( !currentQuote.doneScrolling() )
{
currentQuote.scrollUp( ScrollingGroup.SCROLL_OUT_OF_VIEW );
allScrollingComplete = false;
}

if ( !nextQuote.doneScrolling() )
{
nextQuote.scrollUp( ScrollingGroup.SCROLL_INTO_VIEW );
allScrollingComplete = false;
}

if ( allScrollingComplete )
{
// Reset the quotes
currentQuote.scrollingComplete = false;
nextQuote.scrollingComplete = false;

// Set up the quotes for the next scroll
currentQuote = nextQuote;
nextQuote = ( document.getElementById( currentQuote.getNextQuote() ) ).jsObject;
nextQuote.show();
nextQuote.setVerticalOffset( ( document.getElementById( currentQuote.id) ).offsetHeight + 20 );
window.setTimeout( "scrollQuotes();", timeBetweenScrolls * 1000 );
}

else
{
window.setTimeout( "scrollQuotes();", 50 );
}

}
