/*
 +-------------------------------------------------------------------+
 |                     J S - T I C K E R   (v1.4)                    |
 |                                                                   |
 | Copyright Gerd Tentler               www.gerd-tentler.de/tools    |
 | Created: Oct. 20, 2004               Last modified: Jan. 26, 2007 |
 +-------------------------------------------------------------------+
 | 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 7, Opera 7 + 9, Firefox 2
 - Mac OS X:   IE 5, Safari 1

 If you use another browser or system, this script may not work for you - sorry.

 NOTE: IE 5 on Mac OS doesn't view elements (text etc.) below the ticker area properly; they will
 appear underneath the ticker area instead.
======================================================================================================
*/
//---------------------------------------------------------------------------------------------------------
// Ticker entries
//---------------------------------------------------------------------------------------------------------

var tickerEntries = new Array(
  "Malibu, CA Channel 3 - $125",
  "Carmichael, CA Channel 2 - $219",
  "Stockton, CA Channel 11/69 -  $178",
  "Bakersfield, CA Channel 5 - $155",
  "Thousand Oaks, CA Channel 16 - $175",
  "Mission Viejo, CA Channel 31 - $158",
  "Corte Madera, CA Channel 26 - $95",
  "Temple City, CA Channel 3 - $70",
 	"Roseville, CA Channel 2 - $219",
 	"Ft, Collins, CO Channel 3 - $55",
 	"Glendale, CO Channel 15 - $145",
 	"Colorado Springs, CO Channel 4 - $145",
 	"Pensacola, FL Channel 39 - $65",
 	"Hialeah/Coral Gables, FL Ch 19 - $70",
 	"Tallahassee, FL Channel 21 - $165",
 	"Sebring, FL Channel 4 - $38",
 	"Boca Raton, FL 24 - $88",
 	"Atlanta, GA Channel 19 - $267",
 	"Woodstock, GA Channel 25 - $60",
 	"Cedar Rapids, IA Channel 72 - $150",
 	"Champagne, IL Channel 2  - $122",
 	"Rockford, IL Channel 17 - $67",
 	"Southfield, MI Channel 7 - $92",
 	"Kansas, City, MO Channel 4 - $175",
 	"Monck's, SC Channel 8 - $56",
 	"Eau Clair, WI Channel 16 - $44",
 	"Grand Junction, CO Channel 12 - $33",
 	"Johnstown, PA Channel 9 - $34",
 	"Reno, NV Channel 22  - $75",
 	"Morris Plains, NJ Channel 21 - $64",
 	"Toms River, NJ  18 - $47",
 	"Henderson, NV Channel 48 - $154",
 	"Long Island, NY Channel 18 - $45-$190",
 	"Manhattan, NY Channel 8 - $175",
 	"Medina, OH Channel 23 - $116",
 	"Columbus, OH Channel 7 - $115",
 	"Cleveland, OH  Channel 17 - $260",
 	"Austin, TX Channel 73 - $475",
 	"Champagne, IL  Channel 2 - $76",
 	"Woodlands, TX Channel 74 - $475",
 	"Salt Lake, UT Channel 95 - $41",
 	"Herndon, VA Channel 36 - $165",
 	"Spokane, WA Channel 12/18 - $68",
 	"Olympia, WA Channel 17 - $425",
 	"Wausau, WI Channel 33  - $94",
 	"Cody, WY Channel 13 - $45",
 	"Riverside, CA Channel 3 - $150",
 	"Orange County, CA Channel 16 - $50",
 	"Battle Ground, WA Channel 15 - $80",
 	"Charlotte, NC Channel 9 - $88",
 	"Rohnert Park, CA Channel 6 - $50",
 	"South Portland, ME Channel 5 - $ 75",
 	"Hartford, CT Channel 23 - $95",
 	"Naples, FL Channel 23 - $125",
 	"Dallas TX Channel 15 - $145",
 	"Sandusky, OH Channel 9 - $95",
 	"Palm Springs, CA Channel 4 - $175",
 	"Amarillio TX, Channel 12 - $125"

);

//---------------------------------------------------------------------------------------------------------
// Configuration
//---------------------------------------------------------------------------------------------------------

var tickerWidth = 750;                               // width (pixels)
var tickerMargin = 0;                               // margin (pixels)
var tickerDelay = 30;                                // scrolling delay (smaller = faster)
var tickerSpacer = "   .   ";                            // spacer between ticker entries

var tickerBGColor = "transparent";                       // background color
var tickerHLColor = "transparent";                       // hilight (mouse over) color

var tickerFont = "verdana";  // font family (CSS-spec)
var tickerFontSize = 12;                             // font size (pixels)
var tickerFontColor = "blue";                        // font color

var tickerBorderWidth = 0;                           // border width (pixels)
var tickerBorderStyle = "none";                    // border style (CSS-spec)
var tickerBorderColor = "transparent";                   // border color

//---------------------------------------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------------------------------------

var DOM = document.getElementById;
var IE4 = document.all;

var tickerIV, tickerID;
var tickerItems = new Array();
var tickerHeight = tickerFontSize + 8;

function tickerGetObj(id) {
  if(DOM) return document.getElementById(id);
  else if(IE4) return document.all[id];
  else return false;
}

function tickerObject(id) {
  this.elem = tickerGetObj(id);
  this.width = this.elem.offsetWidth;
  this.x = tickerWidth;
  this.css = this.elem.style;
  this.css.width = this.width + 'px';
  this.css.left = this.x + 'px';
  this.move = false;
  return this;
}

function tickerNext() {
  if(!DOM && !IE4) return;
  var obj = tickerItems[tickerID];
  obj.x = tickerWidth;
  obj.css.left = tickerWidth + 'px';
  obj.move = true;
}

function tickerMove() {
  if(!DOM && !IE4) return;
  for(var i = 0; i < tickerItems.length; i++) {
    if(tickerItems[i].move) {
      if(tickerItems[i].x > -tickerItems[i].width) {
        tickerItems[i].x -= 2;
        tickerItems[i].css.left = tickerItems[i].x + 'px';
      }
      else tickerItems[i].move = false;
    }
  }
  if(tickerItems[tickerID].x + tickerItems[tickerID].width <= tickerWidth) {
    tickerID++;
    if(tickerID >= tickerItems.length) tickerID = 0;
    tickerNext();
  }
}

function tickerStart(init) {
  if(!DOM && !IE4) return;
  if(tickerBGColor) {
    var obj = tickerGetObj('divTicker');
    obj.style.backgroundColor = tickerBGColor;
  }
  if(init) {
    tickerID = 0;
    tickerNext();
  }
  tickerIV = setInterval('tickerMove()', tickerDelay);
}

function tickerStop() {
  if(!DOM && !IE4) return;
  clearInterval(tickerIV);
  if(tickerHLColor) {
    var obj = tickerGetObj('divTicker');
    obj.style.backgroundColor = tickerHLColor;
  }
}

function tickerInit() {
  if(!DOM && !IE4) return;
  for(var i = 0; i < tickerEntries.length; i++) {
    tickerItems[i] = new tickerObject('divTickerEntry' + (i+1));
  }
  var obj = tickerGetObj('divTicker');
  obj.style.width = tickerWidth + 'px';
  obj.style.visibility = 'visible';
  tickerStart(true);
}

function tickerReload() {
  if(!DOM && !IE4) return;
  document.location.reload();
}

window.onresize = tickerReload;
window.onload = tickerInit;

//---------------------------------------------------------------------------------------------------------
// Build ticker
//---------------------------------------------------------------------------------------------------------

document.write('<style> ' +
               '#divTicker { ' +
               'position: absolute; ' +
               'width: 10000px; ' +
               'height: ' + tickerHeight + 'px; ' +
               'cursor: default; ' +
               'overflow: hidden; ' +
               'visibility: hidden; ' +
               (tickerBorderWidth ? 'border-width: ' + tickerBorderWidth + 'px; ' : '') +
               (tickerBorderStyle ? 'border-style: ' + tickerBorderStyle + '; ' : '') +
               (tickerBorderColor ? 'border-color: ' + tickerBorderColor + '; ' : '') +
               '} ' +
               '.cssTickerContainer { ' +
               'position: relative; ' +
               'height: ' + tickerHeight + 'px; ' +
               'margin-top: ' + tickerMargin + 'px; ' +
               'margin-bottom: ' + tickerMargin + 'px; ' +
               '} ' +
               '.cssTickerEntry { ' +
               'font-family: ' + tickerFont + '; ' +
               'font-size: ' + tickerFontSize + 'px; ' +
               'color: ' + tickerFontColor + '; ' +
               '} ' +
               '</style>');

document.write('<div class="cssTickerContainer">' +
               '<div id="divTicker" onMouseOver="tickerStop()" onMouseOut="tickerStart()">');

for(var i = 0; i < tickerEntries.length; i++) {
  document.write('<div id="divTickerEntry' + (i+1) + '" class="cssTickerEntry" ' +
                 'style="position:absolute; top:2px; white-space:nowrap">' +
                 tickerEntries[i] + ((tickerEntries.length > 1) ? ' ' + tickerSpacer + '&nbsp;' : '') +
                 '</div>');
}
document.write('</div></div>');

//---------------------------------------------------------------------------------------------------------
