/*
 +-------------------------------------------------------------------+
 |                     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(
	"My First <a href='http://www.tva.com'>Ticker!</a>",
	"New <a href='#'>ED story</a>",
	"One <a href='#'>more link</a> for you",
	"NuStart Energy Development LLC has selected Bellefonte as one of the nation&rsquo;s two best locations for an advanced technology nuclear-power plant. Under the MOI, the details of the proposed project are confidential."
);

var tickerEntries = new Array();
tickerEntries[0] = document.getElementById("myTicker").innerHTML;

//---------------------------------------------------------------------------------------------------------
// Configuration
//---------------------------------------------------------------------------------------------------------

var tickerWidth = 654;                               // width (pixels)
var tickerDelay = 30;                                // scrolling delay (smaller = faster)
var tickerSpacer = "&nbsp;&bull;&nbsp;";                            // spacer between ticker entries

var tickerBGColor = "#f9dba8";                       // background color
var tickerHLColor = "#f9dba8";                       // 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 = "#000000";                        // font color



// doesn't work properly with NN4:
var tickerBorderWidth = 0;                           // border width (pixels)
var tickerBorderStyle = "solid";                    // border style (CSS-spec)
var tickerBorderColor = "white";                     // border color

//---------------------------------------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------------------------------------

var DOM = document.getElementById;
//if(DOM) alert("DOM");
var IE  = document.all;
//if(IE) alert("IE");
var NN4 = document.layers;
//if(NN4) alert("NN4");

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 + "px";
//  alert("this.width = " + this.width);
//  alert("this.css.width = " + this.css.width);
//  strcss = NN4 ? "this.elem" : "this.elem.style";
//  alert("this.css = " + strcss);
//  alert("this.css.left (before) =" + this.css.left);
  this.left = tickerWidth;
  this.css.left = tickerWidth + "px";
//  alert("tickerWidth =" + tickerWidth);
//  alert("this.left =" + this.left);
//  alert("this.css.left (after) =" + this.css.left);
  this.css.visibility = 'visible';
  this.move = false;
  return this;
}

function tickerNext() {
  if(!DOM && !IE && !NN4) return;
  var obj = tickerArea[tickerID];
  obj.left = tickerWidth;
  obj.css.left = tickerWidth + "px";
  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 + "px";
      }
      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 = "2px";
    width += tickerArea[i].width;
  }
  if(width < tickerWidth) {
    i = tickerArea.length - 1;
    tickerArea[i].width += tickerWidth;
    tickerArea[i].css.width = tickerArea[i].width + "px";
  }
  tickerStart(true);
}

window.onload = tickerInit;

//---------------------------------------------------------------------------------------------------------
// Build ticker
//---------------------------------------------------------------------------------------------------------

var code = '<style> ' +
               '#ticker { ' +
               'width:' + (IE ? tickerWidth + tickerBorderWidth*2 : tickerWidth) + 'px; ' +
               'height:' + (IE ? tickerHeight + tickerBorderWidth*2 : tickerHeight) + 'px; ' +
               'cursor:default; ' +
               '} ' +
               '#tickerContainer { ' +
               'position:absolute; ' +
               'width:' + tickerWidth + 'px; ' +
               'height:' + tickerHeight + 'px; ' +
               'clip:rect(0,' + tickerWidth + ',' + tickerHeight + ',0); ' +
               'overflow: hidden;' + 
               '} ' +
               '.clsTickerEntry { ' +
               'font-family:' + tickerFont + '; ' +
               'font-size:' + tickerFontSize + 'px; ' +
               'color:' + tickerFontColor + '; ' +
               '} ' +
               '</style>';

code = code + '<div id="ticker" onMouseOver="tickerStop()" onMouseOut="tickerStart()">' +
               '<div id="tickerContainer">';

for(var i = 0; i < tickerEntries.length; i++) {
	code = code + '<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>';
}
code = code + '</div></div>';

document.write(code);

//---------------------------------------------------------------------------------------------------------
