/*
======================================================================
 NewsBar v1.2 (modified to Forum Images NewsBar 1.2)
 (c) 2002 VASIL DINKOV- PLOVDIV, BULGARIA
 Vasil Dinkov's NewsBar v1.2 is modified for use and distribution by
 forumimages.com with the author's kind permission.
======================================================================
 Forum Images NewsBar 1.2
 A Forum Images Production -- http://www.forumimages.com/
 Authors: SamG, Daz
 License: FI Free to Use and Distribute - Please see the included licenses.html
	file before using this software. A copy of the license that applies to this script
	can be	found on the Forum Images site should it not be included;
	http://www.forumimages.com/terms.php
======================================================================
*/

var regexpResult = null;
var characterEntities = new Array(), entityIndex = 0;
var imageTags = new Array(), imageTagIndex = 0, loadImage = new Image();
var openTags = new Array(), openTagIndex = 0;
var closeTags = new Array(), closeTagIndex = 0;
for ( var i = 0; i < newsContent.length; i++ ) {
  if ( pauseOnMouseover ) newsContent[i] = newsContent[i].replace(/<a(\s\w+=".+")*>/gi, '<a$1 onmouseout="newsNew();" onmouseover="window.clearTimeout(newsEvent);">');
  if ( regexpResult = newsContent[i].match(/&\w+;/gi) ) {
    for ( var j = 0; j < regexpResult.length; j++ ) {
      characterEntities[entityIndex] = regexpResult[j];
      entityIndex++;
    }
  }
  if ( regexpResult = newsContent[i].match(/<img[^<]+\/>/gi) ) {
    for ( var j = 0; j < regexpResult.length; j++ ) {
      imageTags[imageTagIndex] = regexpResult[j];
      imageTagIndex++;
      loadImage.src = regexpResult[j].replace(/.+src="(.+)".+/i, '$1');
    }
  }
  if ( regexpResult = newsContent[i].match(/<\w+(\s\w+=".+")*>/gi) ) {
    for ( var j = 0; j < regexpResult.length; j++ ) {
      openTags[openTagIndex] = regexpResult[j];
      openTagIndex++;
    }
  }
  if ( regexpResult = newsContent[i].match(/<\/\w+>/gi) ) {
    for ( var j = 0; j < regexpResult.length; j++ ) {
      closeTags[closeTagIndex] = regexpResult[j];
      closeTagIndex++;
    }
  }
}

defaultNewsTimeout *= 1000;
newsTimeout *= 1000;
entityIndex = 0;
imageTagIndex = 0;
openTagIndex = 0;
closeTagIndex = 0;
var closeMarkup = '', contentIndex = 0, cursorPosition = 0;
document.write(defaultNews);
var newsEvent = window.setTimeout('newsNew()', defaultNewsTimeout);

function newsNew() {
  document.getElementById('finewsdisplay').innerHTML = newsContent[contentIndex].substring(0, cursorPosition) + closeMarkup + leadingSign;
  if ( entityIndex < characterEntities.length ) {
    if ( newsContent[contentIndex].substring(cursorPosition, cursorPosition + characterEntities[entityIndex].length) == characterEntities[entityIndex] ) {
      cursorPosition += characterEntities[entityIndex].length - 1;
      entityIndex++;
    }
  }
  if ( imageTagIndex < imageTags.length ) {
    if ( newsContent[contentIndex].substring(cursorPosition, cursorPosition + imageTags[imageTagIndex].length) == imageTags[imageTagIndex] ) {
      cursorPosition += imageTags[imageTagIndex].length - 1;
      imageTagIndex++;
    }
  }
  if ( openTagIndex < openTags.length ) {
    if ( newsContent[contentIndex].substring(cursorPosition, cursorPosition + openTags[openTagIndex].length) == openTags[openTagIndex] ) {
      cursorPosition += openTags[openTagIndex].length;
      openTagIndex++;
    }
  }
  if ( (closeTagIndex < closeTags.length) && (openTagIndex > 0) ) {
    if ( newsContent[contentIndex].substring(cursorPosition, cursorPosition + closeTags[closeTagIndex].length) == closeTags[closeTagIndex] ) {
      cursorPosition += closeTags[closeTagIndex].length - 1;
      closeTagIndex++;
      closeMarkup = '';
    }
    else closeMarkup = closeTags[closeTagIndex];
  }
  if ( cursorPosition++ == newsContent[contentIndex].length ) {
    cursorPosition = 0;
    contentIndex++;
    if ( contentIndex == newsContent.length ) {
      contentIndex = 0;
      entityIndex = 0;
      imageTagIndex = 0;
      openTagIndex = 0;
      closeTagIndex = 0;
    }
    newsEvent = window.setTimeout('newsNew()', newsTimeout);
  }
  else newsEvent = window.setTimeout('newsNew()', newsSpeed);
}

function newsPopUp(uri) {
  var newWindow = window.open(uri, newsPopUpName, newsPopUpFeatures);
}
