
var counter=40
var shrink=200
var maxsize=0
var intHide



// -------------------------------------------------------------------
// tickerobject()- Create new ticker object
// -------------------------------------------------------------------
function tickerobject(content, divId, divClass, delay){

this.content=content //promo 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 ticker (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
this.expandticker=0// Boolean to indicate whether the expand was clicked 
this.isanimating=0;// Boolean to indicate whether the ticker is animating
this.firstload=0;// Boolean to indicate whether the page was just loaded and the ticker has not started to animate

//Everything in 1 Big table
document.writeln('<table class="tickertable" cellpadding="0" cellspacing="0">');

//Everything in 1 Row
document.writeln('<tr>');

// ticker column 1
document.writeln('<td ALIGN="top" VALIGN=TOP HEIGHT=40px>');

// start of outertable
document.writeln('<table id="outertable" class="outertable" cellpadding="0" cellspacing="0" HEIGHT=40px');
document.writeln('<tr>');
document.writeln('<td id="outercolumn1div" class="outercolumn1div" ALIGN="top" VALIGN=TOP>');
//Ticker Div
document.writeln('<div id="'+divId+'" class="'+divClass+'">');
document.writeln('<div class="visibleticker" id="'+divId+'1">'+content[0]+ '</div>');
document.writeln('<div class="hiddenticker" style="visibility: hidden" id="'+divId+'2">'+content[1]+ '</div>');
//ExpandAll Div
document.writeln('<div id="expandalldiv" class="expandalldiv">');
document.writeln('</div>');
document.writeln('</div>');	//end of Ticker Div  
document.writeln('</td>');
document.writeln('</tr>');
document.writeln('</table>');// end of outertable


document.writeln('</td>');// end of ticker column 1

// expand link column 2
//document.writeln('<td ALIGN="top" VALIGN=TOP>');

document.writeln('<table id="expandtable" class="expandtable" cellpadding="0" cellspacing="0">');
//document.writeln('<tr>');
//document.writeln('<td>');

//document.writeln('<table id="outercolumn2div" cellpadding="0" cellspacing="0">');
//document.writeln('<tr>');
//document.writeln('<td width="7px">');
//document.writeln('</td>');
//document.writeln('<td id="outercolumn2div" class="outercolumn2div" width="10px" ALIGN="top" VALIGN=TOP>');
//document.writeln('<img id="imgdisplay" src=\"'+ imgdownarrow+'"/>');
//document.writeln('</td>');
//document.writeln('<td width="5px">');
//document.writeln('</td>');
//document.writeln('<td id="expandcoldiv" class="expandcoldiv">');
//document.writeln(expandtext);
//document.writeln('</td>');
//document.writeln('</tr>');
//document.writeln('</table>');

document.writeln('</td>');
document.writeln('</tr>');
document.writeln('</table>');

document.writeln('</td>');// end of expand link column 2


document.writeln('</tr>');
document.writeln('</table>');




var tickerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){tickerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){tickerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
this.time_out = setTimeout(function(){tickerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize ticker method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

tickerobject.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")



this.visibledivtop=parseInt(tickerobject.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
//document.writeln(this.visibledivtop*2);
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
//this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.width
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var tickerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){tickerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){tickerinstance.mouseoverBol=0}
document.getElementById("expandtable").onclick = function(){tickerinstance.expandticker=1}

setTimeout(function(){ tickerinstance.checkforanimating()},5);

if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){tickerinstance.tickerdiv.onmouseover=tickerinstance.tickerdiv.onmouseout=null})
this.time_out = setTimeout(function(){tickerinstance.animateup()}, this.delay)



}

// -------------------------------------------------------------------
// checkforanimating()- Check every 5 millisecs to see if the ticker is animating
// -------------------------------------------------------------------

tickerobject.prototype.checkforanimating=function(){
var tickerinstance=this
if (tickerinstance.isanimating == 0) 
{

if (tickerinstance.expandticker==1)
{

tickerinstance.expandticker=0;
tickerinstance.expandallhalt();
}
}

setTimeout(function(){ tickerinstance.checkforanimating()},5);
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the ticker up and in sync
// -------------------------------------------------------------------
tickerobject.prototype.animateup=function(){
var tickerinstance=this
//document.writeln(this.hiddendiv.style.top+" "+this.visiblediv.style.top);
this.firstload=1;
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){

tickerinstance.isanimating = 1;
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
this.time_out = setTimeout(function(){tickerinstance.animateup()}, 50)
}
else{

tickerinstance.isanimating = 0;
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()

if (tickerinstance.expandticker==1)
{

}
else
{
tickerinstance.time_out = setTimeout(function(){tickerinstance.setmessage()}, tickerinstance.delay)
}


}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

tickerobject.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

tickerobject.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
//div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
div2.style.top=div1.offsetHeight+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

tickerobject.prototype.setmessage=function(){
var tickerinstance=this
if (tickerinstance.mouseoverBol==1)//if mouse is currently over scoller, do nothing (pause it)
{
tickerinstance.time_out = setTimeout(function(){tickerinstance.setmessage()}, 100)
}
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer];
this.animateup()

}
}

// -------------------------------------------------------------------
// expandallhalt()- Expand the ticker and stop rotating
// -------------------------------------------------------------------

tickerobject.prototype.expandallhalt=function(){
var tickerinstance=this

tickerinstance.showmenu();


}


// -------------------------------------------------------------------
// animate_expand()- Expand the ticker by animating
// -------------------------------------------------------------------


tickerobject.prototype.animate_expand=function()
{
    var tickerinstance=this
   
    if (maxsize-counter >= 5)
    {
        if (counter<maxsize)
	    {
	    counter=counter+5;
	    
	    var tickeriddiv = document.getElementById(tickerinstance.tickerid);
	    tickeriddiv.style.height = counter + "px";
	    intShow = setTimeout(function(){tickerinstance.animate_expand()}, guillotinespeed);
	    }
	}
	else if (maxsize - counter >= 1)
	{
	   
	    counter=counter+1;
	    
	    var tickeriddiv = document.getElementById(tickerinstance.tickerid);
	    tickeriddiv.style.height = counter + "px";
	    intShow = setTimeout(function(){tickerinstance.animate_expand()}, guillotinespeed);
	}
	else
	{
	
	window.clearTimeout(intShow);
	var imgelem = document.getElementById("expandtable");
    imgelem.onclick = function(){tickerinstance.hidemenu()};

    var collelem =  document.getElementById("expandcoldiv");
    collelem.innerHTML = collapsetext;

    var imgs = document.getElementById("imgdisplay");
    imgs.setAttribute('src',imguparrow);
	}

}

// -------------------------------------------------------------------
// showmenu()- Set the max size of the ticker before starting to animate the expand
// -------------------------------------------------------------------
tickerobject.prototype.showmenu=function()
{
    var tickerinstance=this

    var parentdiv = document.getElementById('expandalldiv');
    this.addElements();

    var expalldiv = document.getElementById('expandalldiv');
    this.hiddendiv.innerHTML = expalldiv.innerHTML;


    window.clearTimeout(intHide);



    counter = 40;
    var ceiling=this.content.length
    var hitceiling = ceiling;
    maxsize = (40 * hitceiling) + 35;
    //maxsize = (41 * (hitceiling - 1)) + 40 + 35 + 1
    if (isIE6 )
    {
        maxsize = maxsize + ceiling -1;
    }

    intShow = setTimeout(function(){tickerinstance.animate_expand()}, guillotinespeed);

    window.clearTimeout(tickerinstance.time_out);

}

//get CSS padding value, if any
tickerobject.getCSSpadding=function(tickerobj){ 
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

// -------------------------------------------------------------------
// addElements()- Go through the content array and create new divs and add them to a single div
// -------------------------------------------------------------------
tickerobject.prototype.addElements=function() {
  var tickerinstance=this
  var ni = document.createElement('div');
  var parentdiv = document.getElementById('expandalldiv');
  
  var i=this.hiddendivpointer;
  var ceiling=this.content.length;
  var j = i;
 
  if (this.firstload==0)
  {
    i=0;
  }
  
  j = i+1;
  
 
  while(j<ceiling)
   {  
  
    var newdiv = document.createElement('div');
    newdiv.setAttribute("class","pscroller4");

 
    newdiv.innerHTML = sepdiv + this.content[j];
    ni.appendChild(newdiv);
  

    j = j +1;

  }
  
  var k = 0;
  
  while(k < i)
  {
     var newdiv = document.createElement('div');
     newdiv.setAttribute("class","pscroller4");
     newdiv.innerHTML = sepdiv + this.content[k];
     ni.appendChild(newdiv);

     k = k +1;
  }
  
  
  var viewallpromodiv = document.createElement('div');

  viewallpromodiv.innerHTML=viewallpromodivhtml;

  ni.appendChild(viewallpromodiv);
  
  parentdiv.innerHTML = ni.innerHTML;
  return parentdiv;
}

// -------------------------------------------------------------------
// hide()- Collapse the div through animation
// -------------------------------------------------------------------
tickerobject.prototype.hide=function()
{
var tickerinstance=this
if (shrink>40)
	{
	shrink=shrink-5;
	
    var tickeriddiv = document.getElementById(tickerinstance.tickerid);
	tickeriddiv.style.height = shrink + "px";
	
	intHide = setTimeout(function(){tickerinstance.hide()}, guillotinespeed)
	}
	else
    {
    window.clearTimeout(intHide);
    
    var imgelem = document.getElementById("expandtable");
    imgelem.onclick = function(){tickerinstance.expandticker=1}

    var collelem =  document.getElementById("expandcoldiv");
    collelem.innerHTML = expandtext;

    var imgs = document.getElementById("imgdisplay");
    imgs.setAttribute('src',imgdownarrow);

    var i=this.hiddendivpointer
    var ceiling=this.content.length
    this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
    this.hiddendiv.innerHTML=this.content[this.hiddendivpointer];
    this.animateup()
	}
	
}
// -------------------------------------------------------------------
// hidemenu()- Get the maxsize before the collapse of the div 
// -------------------------------------------------------------------
tickerobject.prototype.hidemenu=function()
{
    var tickerinstance=this

    shrink = maxsize;

    window.clearTimeout(intShow);
    intHide = setTimeout(function(){tickerinstance.hide()}, guillotinespeed);

}
