/*Typing Scroller
Submitted by bengaliboy00@hotmail.com (hp: http://www.angelfire.com/nt/bengaliboy/)
With modifications by Dynamicdrive.com
Additional modifications by jscheuer1 29/Dec/2005
as seen in http://dynamicdrive.com/forums
For full source code, usage terms, and 100s more scripts, visit http://dynamicdrive.com
*/

//Set pause between messages in milliseconds, use 3000 for default:
var pause = 3000

//Set typing speed (higher numbers are slower, use 60 for default)
var speed = 60

//Specify scroller contents and links
/*
var line = new Array()
line[1] = ["This is an awsome script", "http://www.google.com/"]
line[2] = ["One letter at a time", "javascript:void(0)"] //no link syntax
line[3] = ["You can add and subtract lines as you like.", "http://www.yahoo.com/"]
*/
///////////////Stop Editing////////////

/*
if (document.all || document.getElementById) {
    document.write('<a id="banner" href="' + line[1][1] + '" onmousedown="window.location=this.href;return false;" onclick="return false;"></a>')
}

var lines = line.length - 1,*/
var lines, temp = ""
var ban
var line = new Array()
/*ban = document.getElementById ? document.getElementById('banner') : document.all.banner,*/
nextchar = -1,
/*nextline = 1,*/
nextline = 0,
cursor = " ";

//JP-Assign news items to 2-d array lines before starting animation
function PassNewsTickerString(str) {
    myArray = str.split("|#|")
    lines = (myArray.length / 2) - 1
    var i, j = 0
    /*JP-To create two dimensional array, split received string and assign 1st element as caption, 2nd as url
    for all news items*/
    for (i = 0; i <= lines; i++) {
        line[i] = [myArray[j], myArray[j + 1]]
        j = j + 2
    }
}

function animate() {
    //JP
    ban = document.getElementById("NewsTicker")

    if (ban.href.indexOf(line[nextline][1]) == -1)
        ban.href = line[nextline][1]
    ban.style.cursor = /void/.test(ban) ? 'text' : ''
    if (temp == line[nextline][0] & temp.length == line[nextline][0].length & nextline != lines) {
        nextline++;
        nextchar = -1;
        ban.innerHTML = temp;
        temp = "";
        setTimeout("nextstep()", pause)
    }
    else if (nextline == lines & temp == line[nextline][0] & temp.length == line[nextline][0].length) {
        nextline = 0;
        nextchar = -1;
        ban.innerHTML = temp;
        temp = "";
        setTimeout("nextstep()", pause)
    }
    else
        nextstep()
}

function nextstep() {
    cursor = cursor == "_" ? " " : "_"
    nextchar++;
    temp += line[nextline][0].charAt(nextchar);
    ban.innerHTML = temp + cursor
    setTimeout("animate()", speed)
}

/*if (document.all || document.getElementById)
    onload = animate;
*/

/*
An object-oriented Typing Text script, to allow for multiple instances.
A script that causes any text inside any text element to be "typed out", one letter at a time. Note that any HTML tags will not be included in the typed output, to prevent them from causing problems. Tested in Firefox v1.5.0.1, Opera v8.52, Konqueror v3.5.1, and IE v6.
Browsers that do not support this script will simply see the text fully displayed from the start, including any HTML tags.

Functions defined:
  TypingText(element, [interval = 100,] [cursor = "",] [finishedCallback = function(){return}]):
    Create a new TypingText object around the given element.  Optionally
    specify a delay between characters of interval milliseconds.
    cursor allows users to specify some HTML to be appended to the end of
    the string whilst typing.  Optionally, can also be a function which
    accepts the current text as an argument.  This allows the user to
    create a "dynamic cursor" which changes depending on the latest character
    or the current length of the string.
    finishedCallback allows advanced scripters to supply a function
    to be executed on finishing.  The function must accept no arguments.

  TypingText.run():
    Run the effect.

  static TypingText.runAll():
    Run all TypingText-enabled objects on the page.
*/
/*
TypingText = function(element, interval, cursor, finishedCallback) {
  if((typeof document.getElementById == "undefined") || (typeof element.innerHTML == "undefined")) {
    this.running = true;	// Never run.
    return;
  }
  this.element = element;
  this.finishedCallback = (finishedCallback ? finishedCallback : function() { return; });
  this.interval = (typeof interval == "undefined" ? 30 : interval);
  this.origText = this.element.innerHTML;
  this.unparsedOrigText = this.origText;
  this.cursor = (cursor ? cursor : "");
  this.currentText = "";
  this.currentChar = 0;
  this.element.typingText = this;
  if(this.element.id == "") this.element.id = "typingtext" + TypingText.currentIndex++;
  TypingText.all.push(this);
  this.running = false;
  this.inTag = false;
  this.tagBuffer = "";
  this.inHTMLEntity = false;
  this.HTMLEntityBuffer = "";
}
TypingText.all = new Array();
TypingText.currentIndex = 0;
TypingText.runAll = function() {
  for(var i = 0; i < TypingText.all.length; i++) TypingText.all[i].run();
}
TypingText.prototype.run = function() {
  if(this.running) return;
  if(typeof this.origText == "undefined") {
    setTimeout("document.getElementById('" + this.element.id + "').typingText.run()", this.interval);	// We haven't finished loading yet.  Have patience.
    return;
  }
  if(this.currentText == "") this.element.innerHTML = "";
//  this.origText = this.origText.replace(/<([^<])*>/, "");     // Strip HTML from text.
  if(this.currentChar < this.origText.length) {
    if(this.origText.charAt(this.currentChar) == "<" && !this.inTag) {
      this.tagBuffer = "<";
      this.inTag = true;
      this.currentChar++;
      this.run();
      return;
    } else if(this.origText.charAt(this.currentChar) == ">" && this.inTag) {
      this.tagBuffer += ">";
      this.inTag = false;
      this.currentText += this.tagBuffer;
      this.currentChar++;
      this.run();
      return;
    } else if(this.inTag) {
      this.tagBuffer += this.origText.charAt(this.currentChar);
      this.currentChar++;
      this.run();
      return;
    } else if(this.origText.charAt(this.currentChar) == "&" && !this.inHTMLEntity) {
      this.HTMLEntityBuffer = "&";
      this.inHTMLEntity = true;
      this.currentChar++;
      this.run();
      return;
    } else if(this.origText.charAt(this.currentChar) == ";" && this.inHTMLEntity) {
      this.HTMLEntityBuffer += ";";
      this.inHTMLEntity = false;
      this.currentText += this.HTMLEntityBuffer;
      this.currentChar++;
      this.run();
      return;
    } else if(this.inHTMLEntity) {
      this.HTMLEntityBuffer += this.origText.charAt(this.currentChar);
      this.currentChar++;
      this.run();
      return;
    } else {
      this.currentText += this.origText.charAt(this.currentChar);
    }
    this.element.innerHTML = this.currentText;
    this.element.innerHTML += (this.currentChar < this.origText.length - 1 ? (typeof this.cursor == "function" ? this.cursor(this.currentText) : this.cursor) : "");
    this.currentChar++;
    setTimeout("document.getElementById('" + this.element.id + "').typingText.run()", this.interval);
  } else {
	this.currentText = "";
	this.currentChar = 0;
        this.running = false;
        this.finishedCallback();
  }
}

*/
