//---------------------------------------------------------------------------------------------------------
// Ticker entries
//---------------------------------------------------------------------------------------------------------

var tickerEntries = new Array(
"LONG PLAIN FIRST NATION, Man. - The federal government is giving aboriginal people a $110-million boost to help fight diabetes in their communities.",
"SYDNEY, N.S. - Nova Scotia's Chapel Island First Nation's out going chief, Kenneth Basque is appealing the outcome of the July 19th election vote that saw convicted sex offender Wilbert Marshall elected chief. Basque lost the election by five votes. There is no clause in the Indian Act preventing a person convicted of an indictable offence from running for elected office. Following the election, Basque said he w ouldn't bother challenging the vote, saying he was 'more embarrassed than anything' to lose to a convicted sex offender.",
"VANCOUVER - The Supreme Court of Canada will rule Friday on whether or not serial killer Robert Pickton deserves a new trial.",
"FISHER RIVER FIRST NATION, Man. - One adult has died and a male has serious burns after a home on a Manitoba First Nation burned to the ground. Mounties say fire and police were dispatched at 12:15 p.m. to a fire at a home on the Fisher River Cree Nation",
"OTTAWA - The door to a possible compromise on Canada's long census was left open a crack Tuesday, with both Industry Minister Tony Clement and the opposition hinting they might consider changes to the nation's big count.",
"NAIN, N.L. - A discipline committee says it is recommending the removal of Max Blake, the representative for Upper Lake Melville and a suspended member of the Nunatsiavut government in Labrador for remarks made about Inuit women and Inuit at an event last month.The discipline committee found that Blake broke the government's code of conduct on two occasions while attending a research forum in Nain last month, though few details were released about the incidents.",
"BATTLE CREEK, Mich. - Crews were working Tuesday to contain and clean up more than three million litres of oil that poured into a creek and flowed into the Kalamazoo River in southern Michigan, coating birds and fish.Authorities in Battle Creek and Emmett Township warned residents about the strong odour from the oil, which leaked Monday from a 76-centimetre pipeline that carries about 30.",
"VANCOUVER- A pristine swath of wilderness in southeastern B.C. needs ecological protection matching that of a neighbouring world heritage site, says a new report by the UN Educational, Scientific and Cultural Organization.",
"The Ontario Provincial Police (OPP) investigation into irregular financial transactions between provincial government ministries and vendors is continuing.  The investigation by the OPP's Anti-Rackets Branch is focused on irregular financial transactions between vendors and the Ministry of Transportation,  Ministry of Economic Development and Trade and Ministry of Community and Social Services. On July 15, 2010, the OPP executed search warrants on the offices of  the three ministries and seized a large volume of documentary and electronic  records that are currently being reviewed."
);

//---------------------------------------------------------------------------------------------------------
// Configuration
//---------------------------------------------------------------------------------------------------------

var tickerWidth = 850;                               // width (pixels)
var tickerMargin = 2;                               // margin (pixels)
var tickerDelay = 40;                                // scrolling delay (smaller = faster)
var tickerSpacer = "..........";                     // spacer between ticker entries

var tickerBGColor = "#92CD87";                       // background color
var tickerHLColor = "#99FF00";                       // hilight (mouse over) color

var tickerFont = "Arial, Helvetica, sans-serif";  // font family (CSS-spec)
var tickerFontSize = 14;                             // font size (pixels)
var tickerFontColor = "004000";                        // font color

var tickerBorderWidth = 2;                           // border width (pixels)
var tickerBorderStyle = "none";                    // border style (CSS-spec)
var tickerBorderColor = "#92CD87";                   // 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];
  if(!obj.move) {
    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>');

//---------------------------------------------------------------------------------------------------------
