/*
Copyright(C) STAT! Systems, Inc.  All rights reserved world wide.

AUTHOR: Ivan Richmond for STAT! Systems, Inc.
CREATED ON: 7-27-2000
LAST MODIFIED: 7-27-2000

HOW TO SET UP A TICKER ON YOUR WEB PAGE
1. Make a form with NAME="ticker".
2. Make a text field inside "ticker" with NAME="tape".
3. Put field_length and time_increment global variables in your page
   BEFORE you include this file as source.  For example:
   
<script language="JavaScript">
<!---
//Page Variables
var field_length     = 50;    // The length of the ticker in characters
var time_increment   = 100;   // The time between iterations in miliseconds
--->
</script>
<script language="JavaScript" src="scripts/ticker.js"></script>

4. Put the text you want for the ticker in the VALUE property of your text
   field.
5. Put a <script> line AFTER your text field that calls start_ticker().
   For example:
   
<script language="JavaScript"> start_ticker(); </script>

6. 
*/


var position = 0;
var ticker_running = false;
var id;
function ticker_tape(){
//
// Copyright(C) 2000 STAT! Systems, Inc.  All rights reserved worldwide.
// AUTHOR: Ivan Richmond for STAT!
// 
// This program runs a ticker tape.
// The concept is that we have a bunch of text that moves through a little 
// box over and over again.
//
// We make the box with a text field in a form.
// We need to make it monotype so that we know how many characters are going
// to fill it so we use the STYLE property in the INPUT tag as follows:
// STYLE="font: 10pt Monotype"
// We set the text field to a character length and assign a constant
// (field_length) in our program to it.
// (I haven't found a way to discover this for a text field dynamically.)
// We then put the text in the ticker tape field_length characters at a time.
// We make it "move" by incrementing the starting and ending positions.
// When we get to the end of the "tape", we start over with position 0.
// For example, let's suppose field_length is 50.
// First time through, we put in characters 0-50.
// Second time we put in 1-51, etc.  
// When we get to the end, we put in 0-50 again.
// In order to make the "tape" come in on the "right",
// we put field_length spaces in front of it.
//

   // Variables
   var field_length     = 50;    // The length of the ticker in characters
   var time_increment   = 100;   // The increment in miliseconds between 
                                 // each character change of the ticker tape
   var iteration        = 0;     // Generic for loop counter
   var spacer           = '';    // A line of spaces to fill the ticker
                                 // so that the text comes in on the right.
   var text             = document.ticker.tape.defaultValue;
                                 // The text for the ticker
   
   // Fill the front of the text with a line of spaces
   // The size of the ticker field.
   for (iteration=1;iteration<field_length;iteration++) {
      spacer += ' ';
   }
   text = spacer + text;
   
   // Run the text through the ticker.
   var text_length = text.length; 
   document.ticker.tape.value = text.substring(position,position+field_length);
   position++;
   if (position>=text_length){position=0;}
   id = setTimeout("ticker_tape();",time_increment); // Repeats in time_increment
                                                     // miliseconds.
   ticker_running = true;
}

function stop_ticker() { // Stops the ticker tape from running.
   clearInterval(id);
   ticker_running = false;   
}

function start_ticker() { // Starts the ticker tape up.
   stop_ticker();
   ticker_tape();
}