/*
 +-------------------------------------------------------------------+
 |                     J S - T I C K E R   (v1.0)                    |
 |                                                                   |
 | Copyright Gerd Tentler               www.gerd-tentler.de/tools    |
 | Created: Oct. 20, 2004               Last modified: Apr. 28, 2005 |
 +-------------------------------------------------------------------+
 | This program may be used and hosted free of charge by anyone for  |
 | personal purpose as long as this copyright notice remains intact. |
 |                                                                   |
 | Obtain permission before selling the code for this program or     |
 | hosting this software on a commercial website or redistributing   |
 | this software over the Internet or in any other medium. In all    |
 | cases copyright must remain intact.                               |
 +-------------------------------------------------------------------+

======================================================================================================
 This script was tested with the following systems and browsers:

 - Windows XP: IE 6, NN 4, NN 7, Opera 7, Firefox 1
 - Mac OS X:   IE 5, Safari 1

 If you use another browser or system, this script may not work for you - sorry.
 NOTE: With Safari 1 (Mac OS X) performance is very poor, i.e. ticker speed is too slow.
======================================================================================================
*/
//---------------------------------------------------------------------------------------------------------
// Ticker entries
//---------------------------------------------------------------------------------------------------------

var tickerEntries = new Array(
  "The caterpillar does all the work but the butterfly gets all the publicity <b>George Carlin</b>",
  "The man who stops advertising to save money is like the man who stops the clock to save time <b>Anonymous</b>.",
  "Good advertising does not just circulate information. It penetrates the public mind with desires and belief  <b>Leo Burnett</b>",
  "You can't do today's job with yesterday's methods and be in business tomorrow. <b>Anonymous</b>",
  "Everything you do is public relations. <b>Anonymous</b>"  
);

//---------------------------------------------------------------------------------------------------------
// Configuration
//---------------------------------------------------------------------------------------------------------

var tickerWidth = 650;                               // width (pixels)
var tickerDelay = 35;                                // scrolling delay (smaller = faster)
var tickerSpacer = "|";                            // spacer between ticker entries

var tickerBGColor = "";                       // background color
var tickerHLColor = "";                       // hilight (mouse over) color (doesn't work with NN4)

var tickerFont = "Verdana, Arial, Helvetica, sans-serif";  // font family (CSS-spec)
var tickerFontSize = 10;                             // font size (pixels)
var tickerFontColor = "black";                        // font color

// doesn't work properly with NN4:
var tickerBorderWidth = 0;                           // border width (pixels)
var tickerBorderStyle = "";                    // border style (CSS-spec)
var tickerBorderColor = "";                     // border color

//---------------------------------------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------------------------------------

var DOM = document.getElementById;
var IE  = document.all;
var NN4 = document.layers;

var iv, tickerID;
var tickerArea = new Array();
var tickerHeight = tickerFontSize + 8;

function tickerObject(obj, cont) {
  cont = cont ? 'document.' + cont + '.' : '';
  if(DOM) this.elem = document.getElementById(obj);
  else if(NN4) this.elem = eval(cont + 'document.' + obj);
  else if(IE) this.elem = document.all[obj];
  this.css = NN4 ? this.elem : this.elem.style;
  this.width = NN4 ? this.elem.document.width : this.elem.offsetWidth;
  this.css.width = this.width;
  this.left = this.css.left = tickerWidth;
  this.css.visibility = 'visible';
  this.move = false;
  return this;
}

function tickerNext() {
  if(!DOM && !IE && !NN4) return;
  var obj = tickerArea[tickerID];
  obj.left = obj.css.left = tickerWidth;
  obj.move = true;
}

function tickerMove() {
  if(!DOM && !IE && !NN4) return;
  for(var i = 0; i < tickerEntries.length; i++) {
    if(tickerArea[i].move) {
      if(tickerArea[i].left > -tickerArea[i].width) {
        tickerArea[i].left -= 2;
        tickerArea[i].css.left = tickerArea[i].left;
      }
      else tickerArea[i].move = false;
    }
  }
  if(tickerArea[tickerID].left + tickerArea[tickerID].width <= tickerWidth) {
    tickerID++;
    if(tickerID >= tickerEntries.length) tickerID = 0;
    tickerNext();
  }
}

function tickerStart(init) {
  if(!DOM && !IE && !NN4) return;
  if(tickerBGColor) {
    if(DOM) document.getElementById('ticker').style.backgroundColor = tickerBGColor;
    else if(NN4) document.ticker.bgColor = tickerBGColor;
    else if(IE) document.all.ticker.style.backgroundColor = tickerBGColor;
  }
  if(init) {
    tickerID = 0;
    tickerNext();
  }
  iv = setInterval('tickerMove()', tickerDelay);
}

function tickerStop() {
  if(!DOM && !IE && !NN4) return;
  clearInterval(iv);
  if(tickerHLColor) {
    if(DOM) document.getElementById('ticker').style.backgroundColor = tickerHLColor;
    else if(NN4) document.ticker.bgColor = tickerHLColor;
    else if(IE) document.all.ticker.style.backgroundColor = tickerHLColor;
  }
}

function tickerInit() {
  if(!DOM && !IE && !NN4) return;
  for(var i = width = 0; i < tickerEntries.length; i++) {
    tickerArea[i] = new tickerObject('tickerEntry' + (i+1), 'ticker.document.tickerContainer');
    tickerArea[i].css.top = 2;
    width += tickerArea[i].width;
  }
  if(width < tickerWidth) {
    i = tickerArea.length - 1;
    tickerArea[i].width += tickerWidth;
    tickerArea[i].css.width = tickerArea[i].width;
  }
  tickerStart(true);
}

window.onload = tickerInit;

//---------------------------------------------------------------------------------------------------------
// Build ticker
//---------------------------------------------------------------------------------------------------------

document.write('<style> ' +
               '#ticker { ' +
               'width:' + (IE ? tickerWidth + tickerBorderWidth*2 : tickerWidth) + 'px; ' +
               'height:' + (IE ? tickerHeight + tickerBorderWidth*2 : tickerHeight) + 'px; ' +
               'cursor:default; ' +
               'float:left; ' +
               (NN4 ? 'position:relative; ' : '') +
               ((tickerBorderWidth && !NN4) ? 'border-width:' + tickerBorderWidth + 'px; ' : '') +
               ((tickerBorderStyle && !NN4) ? 'border-style:' + tickerBorderStyle + '; ' : '') +
               ((tickerBorderColor && !NN4) ? 'border-color:' + tickerBorderColor + '; ' : '') +
               '} ' +
               '#tickerContainer { ' +
               'position:absolute; ' +
               'width:' + ((IE || NN4) ? tickerWidth : 10000) + 'px; ' +
               'height:' + tickerHeight + 'px; ' +
               'clip:rect(0,' + tickerWidth + ',' + tickerHeight + ',0); ' +
               '} ' +
               '.clsTickerEntry { ' +
               'font-family:' + tickerFont + '; ' +
               'font-size:' + tickerFontSize + 'px; ' +
               'color:' + tickerFontColor + '; ' +
               '} ' +
               '</style>');

document.write('<div id="ticker" onMouseOver="tickerStop()" onMouseOut="tickerStart()">' +
               '<div id="tickerContainer">');

for(var i = 0; i < tickerEntries.length; i++) {
  document.write('<div id="tickerEntry' + (i+1) + '" style="position:absolute; visibility:hidden">' +
                 '<table border=0 cellspacing=0 cellpadding=0><tr>' +
                 '<td class="clsTickerEntry" nowrap>' + tickerEntries[i] +
                 ((tickerEntries.length > 1) ? '&nbsp;' + tickerSpacer + '&nbsp;' : '') +
                 '</td></tr></table></div>');
}
document.write('</div></div>');

//---------------------------------------------------------------------------------------------------------
