﻿/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay, height, haveMul){
if(content.length == 0 )return;
this.haveMull = haveMul;
this.TOTAL_HEIGHT = 120;
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
this.controls = new Array();
var arrControl = '';
var top  ;
var offsetHeight = 123;
for(var i = 1;i <= this.content.length;i++)
{
    if(i==1)
    {
      top = 5;
    }
    else
    {
      top = offsetHeight * (i - 1)
    }
    arrControl += '<div class="innerDiv" style="position: absolute; width: 100%;top:' + String(top) + 'px" id="' + divId + String(i) + '">'+content[i-1]+'</div>'
}

document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden;height:' + height + 'px !important;">' + arrControl + '</div>')

var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.createControl();
this.tickerdiv=document.getElementById(this.tickerid)
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
//this.getinline(this.visiblediv, this.hiddendiv)
if(Number(this.haveMull) == 1)
{
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------
var countH = 0;
var begin = 1;
var lastTop= 1;
pausescroller.prototype.animateup=function(){
  var scrollerinstance=this

    if (countH < this.TOTAL_HEIGHT){
    for(var i = begin; i <= this.content.length;i++)
    {
       var objDiv = this.controls[i]
       
       objDiv.style.top = parseInt(objDiv.style.top) - 5 + "px"
       lastTop = objDiv.style.top
    }
    for(var j = 1; j < begin;j++)
    {
       var objDiv = this.controls[j]
       objDiv.style.top = parseInt(objDiv.style.top) - 5 + "px"
       lastTop = objDiv.style.top
    }
    countH += 5;
  setTimeout(function(){scrollerinstance.animateup()}, 50)
    
  }
  else{
  this.controls[begin].style.top = parseInt(lastTop) + this.TOTAL_HEIGHT + "px";

  begin++;
  if(begin > this.content.length)
  {
    begin = 1;
  }
    countH = 0;
    setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
  }
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.createControl=function(){
  for(var i = 1; i <= this.content.length;i++)
  {
    var objDiv = document.getElementById(this.tickerid + i)
    this.controls[i] = objDiv;
  }
}

pausescroller.prototype.getinline=function(div1, div2){
  var beforeDiv
  var offsetHeight;
  for(var i = 1; i <= this.content.length;i++)
  {
   var objDiv = document.getElementById(this.tickerid + i)
    if(i==1)
    {
      objDiv.style.top = this.visibledivtop+"px"
      offsetHeight = objDiv.offsetHeight
    }
    else
    {
      objDiv.style.top = offsetHeight * (i - 1) + "px"
    }
  }
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
  this.animateup()
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}