/*
 Ticky-Ticky Tape Ticker
 (C) 2003 by Alejandro Guerrieri - Magicom
 alejandro@magicom-bcn.net
 
ticker_name: should be a unique name for each ticker you place on your web page.
message: is the message to be rotated. Plain text only, no HTML yet (sorry).
speed: is, as you guessed, the speed for the ticker. Smaller is faster.
direction: is 1 for left to right and -1 for right to left.
*/

var direction = new Array();
var temporary = new Array();
//This do the real job (moves the ticker)
function move_ticker( mess, speed, msg_start, msg_end, fname ) {
  var doc = eval(''+fname+'.scroll');
  var len = doc.size;
  var dir = direction[fname];
  if (dir > 0) {
    if (msg_end >= mess.length) {
      mess = mess.substring(msg_start, mess.length) + mess.substring(0, msg_start);
      msg_start = 0;
      msg_end = len;
    }
  } else {
    if (msg_start <= 0) {
      mess = mess.substring(msg_end, mess.length) + mess.substring(0, msg_end);
      msg_start = mess.length - msg_end;
      msg_end = mess.length;
    }
  }
  doc.value=mess.substring(msg_start, msg_end);
  msg_start+= dir;
  msg_end+= dir;
  window.setTimeout("move_ticker('"+mess+"', "+speed+", "+msg_start+", "+msg_end+", '"+fname+"')", speed);
}

//This inits the ticker and starts the movement. Executed only once at startup time
function init_ticker(fname, mess, speed, dir) {
  var len = eval(''+fname+'.scroll.size');
  direction[fname] = dir;
  while (mess.length < len) {
    mess = '' + mess + mess;
  }
  window.setTimeout("move_ticker('"+mess+"', "+speed+", 0, "+len+", '"+fname+"')", speed);
}

//This switches the tickerīs state (stop or start)
function switch_ticker(fname) {
  if (direction[fname] != 0) {
    temporary[fname] = direction[fname];
    direction[fname] = 0;
  } else {
    direction[fname] = temporary[fname];
  }
}

//This restarts the movement after a stop
function start_ticker(fname) {
	temporary[fname] = -1
   direction[fname] = temporary[fname];	
}

//This stops the ticker
function stop_ticker(fname) {
  temporary[fname] = direction[fname];
  direction[fname] = 0;
}

//This reverts the tickerīs direction
function revert_ticker(fname) {
  temporary[fname] = -temporary[fname];
  direction[fname] = -direction[fname];
}

