/*Created by Rick Bull (http://www.rickmusic.co.uk/ and  http://www.rickmusic.fsnet.co.uk/) - 28 Feb 2001.
 You are free to distribute and use this script anyway you like but please leave this comment here. Thanks.*/
 
//YOU CAN EDIT THESE:
//The time between updates
var updateInterval = 100;
//The time between updates when changing strings
var pauseBetweenStrings = 3000;
//What gets add to the string in increment mode while there is more text - set to '' for nothing
var addToIncrementString = '_'
//What gets add in between the strings in squash mode (default = ' ')
var addToSquashString = ' '
//The number of spaces to add on the sliding mode
var slideSpacesPadding = 25;



//LEAVE THESE ALONE:
//The maximum amount of spaces to add when using slide mode
var maxSlideSpaces = -1;
//The amount of spaces to add when using slide or squash scroll-mode
var addSpaces = 0;
//The position of the string that we are to draw upto
var currentPosition = 0;
//The string that we are on
var currentArray = 0;
//The maximum amount of spaces to add when using squash or squash2 scroll-mode
var maxSquashSpaces = 30;
//The handle of the timer so that it can be stopped
var timerHandle = null;
//The split strings that are to be scrolled
var outputStrings = new Array();

//Scroll mode constants
var increment = 0; //Adds another letter to the text
var slide = 1; //Moves text left from the right
var squash = 2; //Reduces the spaces between text characters
var squash2 = 3 //Slides the last char one less each time

//Splits the strings into the array
function loadStrings(delimitedStrings, delimiterChar)
 {
  //For loops
  var loopCounter;

  //If no delimiter is parsed set it to ';'
  if (delimiterChar == null) delimiterChar = ';';
  //Split the strings to the array
  outputStrings = delimitedStrings.split(delimiterChar);
  //Set the current array/posoition to the first
  currentArray = 0;
  currentPosition = 0;

  //Minimum value so that we will find the biggest one
  maxSlideSpaces = -1;
  //Loop for all strings
  for(loopCounter = 0; loopCounter < outputStrings.length; loopCounter++)
   {
    //If this one is bigger make the maxSlideSpaces = this one's length
    if (outputStrings[loopCounter].length > maxSlideSpaces) maxSlideSpaces = outputStrings[loopCounter].length;
   } 
  //Add the padding to the spaces
  maxSlideSpaces +=  slideSpacesPadding;

  return true;
 }

function startScroller(scrollMode)
 {
  //If scroll mode is not specified use a random one
  if (scrollMode == null) scrollMode = (Math.round(squash2 * Math.random()) + increment);
  //Stop a current scroller
  stopUpdates();
  //Set the current array/posoition to the first
  currentArray = 0;
  currentPosition = 0;
  //Select the appropriate scroll mode
  if (scrollMode == slide) 
   {
    //Set the addSpaces to the maximum
    addSpaces = maxSlideSpaces;
    /*Start the scroller */
    slideText();
   }
  //Start it
  else if (scrollMode == increment) incrementText();
  else if (scrollMode == squash) 
   {
    //Set addSpaces to maxSquashSpaces so as to start with the spaced out text, man!
    addSpaces = maxSquashSpaces;
    //Start the scroller
    squashText();
   }
  else if (scrollMode == squash2) 
   {
    //Set addSpaces to maxSquashSpaces so as to start with the spaced out text, man!
    addSpaces = maxSquashSpaces;
    //Start the scroller
    squashText2();
   }

  return true;
 }

function squashText2()
 {
  //If we are to move on to the next char in the current string
  if (currentPosition < (outputStrings[currentArray].length) && addSpaces == 0) 
   {
    //Increment the current position
    currentPosition++;
    //Set the amount of spaces to the maximum
    addSpaces = maxSquashSpaces
   }
  //If we can take spaces away from the current string take one away
  else if (currentPosition < outputStrings[currentArray].length && addSpaces > 0) addSpaces--;
  //Next string
  else
   {
    //Start of the string
    currentPosition = 0;
    //Maximum spaces
    addSpaces = maxSquashSpaces;
    //If there are more strings increment the current one
    if (currentArray < outputStrings.length - 1) currentArray++;
    //If there aren't back to the start
    else currentArray = 0;
   }

  //Output the status with the spaces
  window.status = (outputStrings[currentArray].substring(0, currentPosition) + repeatString(addToSquashString, addSpaces) + outputStrings[currentArray].substring(currentPosition, currentPosition + 1));
  //If we have completed the current string make the update time large
  if (currentPosition == outputStrings[currentArray].length - 1 && addSpaces == 0) timerHandle = setTimeout('squashText2()', pauseBetweenStrings);
  //If we haven't make it small
  else timerHandle = setTimeout('squashText2()', updateInterval);

  return true;
 }

function slideText()
 {
  //What appears in the status bar
  var statusText = '';
  //Default update time = small
  var currentUpdateInterval = updateInterval;
  
  //If we can subtract spaces and all the string is visible
  if (addSpaces >= 0 && currentPosition >= outputStrings[currentArray].length) 
   {
    //Decremenet the amount of spaces
    addSpaces--;
    //Add the specified amount of spaces to the status text
    statusText = (repeatString(' ', addSpaces) + outputStrings[currentArray]);
    //If we are at the start of the string without any spaces
    if (addSpaces == 0 && currentPosition == outputStrings[currentArray].length) 
     {
      //Update time = large
      currentUpdateInterval = pauseBetweenStrings;
      //Set currentPosition to 0 so as to go to the next if statement 
      currentPosition = 0;
     }    
   }
  //If there are spaces to be removed and all the string isn't visible
  else if (addSpaces > 0 && currentPosition < outputStrings[currentArray].length)
   {
    //Increment currentPosition so as to show a bit more 
    currentPosition++;
    //Remove some spaces so as the text comes back as well as relevaling more of the text
    addSpaces--;
    //Set the text
    statusText = (repeatString(' ', addSpaces) + outputStrings[currentArray].substring(0, currentPosition));
   }
  //If we can remove no more spaces - i.e. we are within the text
  else if (currentPosition < outputStrings[currentArray].length - 1)
   {
    //Increment the current position
    currentPosition++;
    //Set the status text to a bit less than the last
    statusText = outputStrings[currentArray].substring(currentPosition, outputStrings[currentArray].length);
   }
  //If we are at the end of the text
  else 
   {
    //Set the spaces to the most
    addSpaces = maxSlideSpaces;
    currentPosition = 0;
    //If there are more strings increment the current number
    if (currentArray < outputStrings.length - 1) currentArray++;
    //If not start again
    else currentArray = 0;
    //Set the status text to nothing
    statusText = '';
   }

  //Set the status
  window.status = statusText
  //Call this again in the specified time
  timerHandle = setTimeout('slideText()', currentUpdateInterval);

  return true;
 }

function squashText()
 {
  //What appears in the status bar
  var statusText = '';
  //Default update time = small
  var currentUpdateInterval = updateInterval;
  //For loops
  var loopCounter;

  //Loop for all chars in the current string
  for (loopCounter = 0; loopCounter < outputStrings[currentArray].length; loopCounter++)
   {
    //Make the status = the current char + the amount of characters spaces
    statusText += (outputStrings[currentArray].substring(loopCounter, loopCounter + 1) + repeatString(addToSquashString, addSpaces));
   } 

  if (addSpaces == 0) 
   {
    currentUpdateInterval = pauseBetweenStrings;
    addSpaces = maxSquashSpaces;
    if (currentArray < outputStrings.length - 1) currentArray++;
    else currentArray = 0;
   }
  else addSpaces--;

  //Set the status
  window.status = statusText;
  //Set the timer for this function
  timerHandle = setTimeout('squashText()', currentUpdateInterval);

  return true;
 }

function incrementText()
 {
  //What appears in the status bar
  var statusText = '';

  //If there is more text to add increment the current position
  if (currentPosition < outputStrings[currentArray].length) currentPosition++;
  //If we have used all the text in this array
  else
   {
    //If there are more strings
    if (currentArray < outputStrings.length - 1) 
     {
      //Move to next string in the array
      currentArray++;
      //Make our current position the start of the string
      currentPosition = 0;
     }
    //If we have used all the strings in the array
    else 
     {
      //Start again
      currentArray = 0;
      currentPosition = 0;
     }
   }

  //Get the status text
  statusText = outputStrings[currentArray].substring(0, currentPosition);
  //If there is more text to come add the addToString to the end
  if (currentPosition < outputStrings[currentArray].length) statusText += addToIncrementString;
  //Set the current string
  window.status = statusText;

  //If there is more text to add set the timeout to the short length
  if (currentPosition < outputStrings[currentArray].length) timerHandle = setTimeout('incrementText()', updateInterval);
  //If the next one is the start of the next string in the array set the timeout to the long length
  else timerHandle = setTimeout('incrementText()', pauseBetweenStrings);

  return true;
 }

//Stops the status bar scrolling
function stopUpdates()
 {
  //If there is a timer
  if (timerHandle != null) 
   {
    //Stop it
    clearTimeout(timerHandle);
    //Set the var to no timer
    timerHandle = null;
   }

  return true;
 }

//Returns a string that has the specified repeated the amount of time specified 
function repeatString(stringToRepeat, timesToRepeat)
 {
  //The modified string to return
  var returnString = '';
  //For loops
  var loopCounter;
  //Loop for amount wanted
  for (loopCounter = 1; loopCounter <= timesToRepeat; loopCounter++)
   {
    //Add it to the returnString
    returnString += stringToRepeat;
   }

  //Return the modified string
  return returnString;
 }