
var counter=40
var shrink=200
var maxsize=0
var intHide
var DisplayViewAllPromo = true;
var largeTextEnabled = false;

function PromoContent( countdown, index, promotitle, promotitlelen,promourl, promodesc, promodesclen, ismoredetailsdisplay, moredetailsdesc )
{
    this.countdown = countdown;
    this.index = index;
	this.Promotitle = promotitle;
	this.PromotitleLen = promotitlelen;
	this.Promourl = promourl;
	this.Promodesc = promodesc;
	this.Ismoredetailsdisplay = ismoredetailsdisplay;
	this.Moredetailsdesc = moredetailsdesc;
	this.PromodescLen = promodesclen;
	this.RenderPromo     = PromoContentRender;
  
}

function PromoContentRender()
{

          var pcontent;
          var maxpromotitlelen = this.PromotitleLen;
          var maxpromodesclen  = this.PromodescLen;
          if ( twidth > 120)
          {
              var tmp = twidth -120;
              if (this.PromotitleLen > tmp)
              {
                maxpromotitlelen = tmp;
              }
              
              if (this.PromodescLen > tmp)
              {
                maxpromodesclen = tmp;
              }
               
               
            
          }
          pcontent = "<table class=tickertext cellpadding=0 cellspacing=0 border=0><tr><td height=5px></td></tr><tr><td colspan=2><a href=\"" + this.Promourl + "\" class=titledisplay><div id=\"titletxtid" + this.index + "\" class=\"titletxt\" style=\"width:"+maxpromotitlelen+"px;float:left;\">" +this.Promotitle + "</div><div id=\"ellipsesid" + this.index + "\" style=\"float:left;display:none\">...</div></a></td></tr><tr><td class=promodesc><div id=\"desctxtid"+ this.index +"\" class=\"desctxt\" style=\"width:"+maxpromodesclen+"px;float:left;\" align=left>"+this.Promodesc;
          
          if (this.countdown != null)
          {
            pcontent = pcontent + " " + this.countdown;
          }
          if (this.Ismoredetailsdisplay == "true")
                   {
                      pcontent = pcontent + "<span align=left><a href=\"" + this.Promourl + "\" class=detailsdesc>&nbsp;" +this.Moredetailsdesc + "</a></span>";
                   }
                   pcontent = pcontent + "</div><div id=\"ellipsesid_a" + this.index + "\" style=\"float:left;display:none\">...</div></td></tr><tr><td height=5px></td></tr></table>";
          
         
          return pcontent;
                                
}



function RenderViewAllPromo(viewallpromourl, imgsrc, viewallpromotxt)
{
     var viewAllPromo;
     
     if ((viewallpromotxt == null) || (viewallpromotxt == ""))
     {
     DisplayViewAllPromo = false;
     return;
     }
     viewAllPromo = "<table cellspacing=0 cellpadding=0 class=\"viewallpromo\"><tr><td width=\"10px\"></td><td width=\"5px\" align=\"left\"><a href=\""+ viewallpromourl +"\"><img style=\"border: none; border-color: #000000\" src=\"" + imgsrc + "\" align=\"center\"></img></a></td><td width=\"3px\"></td><td padding-left=\"0px\" align=\"left\"><a class=\"viewallrefclass\" href=\"" + viewallpromourl + "\">" + viewallpromotxt + "</a></td></tr><table>";
     return viewAllPromo;
}

function RenderDivider()
{
     var rdiv = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td width=\"10px\"></td><td colspan=2 width=\"620px\" height=\"1px\" bgcolor=\"#D48D3F\"><div><img src=\"" + m_imgPfx + "/images/global/general/spacer.gif\" height=\"1\" width=\"100%\"></img></div></td></tr></table>";
    
     return rdiv;
}


var twidth = 0;
// -------------------------------------------------------------------
// tickerobject()- Create new ticker object
// -------------------------------------------------------------------
function tickerobject(content, divId, divClass, delay, width){

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
this.tickerwidth = width;
twidth = width;
this.tdHeight = 0;
if (largeTextEnabled == "true")
{
    this.tdHeight = 55;
}
else
{
    this.tdHeight = 40;
}

//Everything in 1 Big table
document.writeln('<table class="tickertable" cellpadding="0" cellspacing="0" width=\"'+width+'\px">');

//Everything in 1 Row
document.writeln('<tr>');

// ticker column 1
document.writeln('<td ALIGN="top" VALIGN=TOP HEIGHT=40px width=100%>');

// start of outertable
document.writeln('<table id="outertable_'+divId+'" class="outertable" cellpadding="0" cellspacing="0" HEIGHT=40px width=100%');
document.writeln('<tr>');
document.writeln('<td id="outercolumn1div_'+divId+'" class="outercolumn1div" ALIGN="top" VALIGN=TOP>');
//Ticker Div
document.writeln('<div id="'+divId+'" class="'+divClass+'" style=height:'+ this.tdHeight + 'px;>');

document.writeln('<div class="visibleticker"  id="visibleticker_'+divId+'">'+content[0].RenderPromo() + '</div>');
var contenttmp = content[1];
if (contenttmp == null)
{
contenttmp = content[0];
}
document.writeln('<div class="hiddenticker" style="visibility: hidden" id="hiddenticker_'+divId+'">'+contenttmp.RenderPromo() + '</div>');
//ExpandAll Div
document.writeln('<div id="expandalldiv_'+divId+'" 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_'+divId+'" class="expandtable" cellpadding="0" cellspacing="0" style=height:'+ this.tdHeight + 'px; >');
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><img id="imgdisplay_'+divId+'" src=\"'+ imgdownarrow+'"/></td>');
document.writeln('<td width="5px">');
document.writeln('</td>');
document.writeln('<td id="expandcoldiv_'+divId+'" 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("visibleticker_"+this.tickerid)
this.hiddendiv=document.getElementById("hiddenticker_"+this.tickerid)


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)

this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
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_"+tickerinstance.tickerid).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)

SetDisplayOfEllipsesForTitles(0);
SetDisplayOfEllipsesForTitleDesc(0);

}

// -------------------------------------------------------------------
// 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
SetDisplayOfEllipsesForTitles(this.hiddendivpointer);
SetDisplayOfEllipsesForTitleDesc(this.hiddendivpointer);
if (this.content.length == 1)
{
return;
}
//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=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].RenderPromo();

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_"+tickerinstance.tickerid);
        imgelem.onclick = function(){tickerinstance.hidemenu()};

        var collelem =  document.getElementById("expandcoldiv_"+tickerinstance.tickerid);
        collelem.innerHTML = collapsetext;
           
        var imgs = document.getElementById("imgdisplay_"+tickerinstance.tickerid);
        imgs.setAttribute('src',imguparrow);
	}
}

tickerobject.prototype.PolishTitles=function()
{
    var ceiling=this.content.length;
    
    var i = 0
    while (i < ceiling)
    {
        
        SetDisplayOfEllipsesForTitles(i);
        i = i + 1 ;
    }
}

tickerobject.prototype.PolishTitleDesc=function()
{
    var ceiling=this.content.length;
    
    var i = 0
    while (i < ceiling)
    {
        
        SetDisplayOfEllipsesForTitleDesc(i);
        i = i + 1 ;
    }
}

function SetDisplayOfEllipsesForTitles(i)
{
        var obj = document.getElementById("titletxtid" + i);
        if (obj != null)
        {
            if (obj.scrollWidth > obj.clientWidth)
            {
              
                var e_obj = document.getElementById("ellipsesid" + i);
                e_obj.style.display = "block";
            }  
        }
}

function SetDisplayOfEllipsesForTitleDesc(i)
{
        var obj = document.getElementById("desctxtid" + i);
        if (obj != null)
        {
            if (obj.scrollWidth > obj.clientWidth)
            {
              
                var e_obj = document.getElementById("ellipsesid_a" + i);
                e_obj.style.display = "block";
            }  
        }
}


// -------------------------------------------------------------------
// 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_'+tickerinstance.tickerid);
    this.addElements();

    var expalldiv = document.getElementById('expandalldiv_'+tickerinstance.tickerid);
    this.hiddendiv.innerHTML = expalldiv.innerHTML;
    
    this.PolishTitles();
    this.PolishTitleDesc();
    
    window.clearTimeout(intHide);

    if (largeTextEnabled == "true")
    {
        counter = 50;
    }
    else
    {
        counter = 40;
    }
    //counter = 40;
    
    var ceiling=this.content.length
    var hitceiling = ceiling;
    //maxsize = (40 * hitceiling);
    maxsize = (counter * hitceiling);
   
    if (DisplayViewAllPromo)
    {
     maxsize =   maxsize + 35;
     if (largeTextEnabled == "true")
     {
     maxsize = maxsize - 10;
     }
    }
 
    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_'+tickerinstance.tickerid);
  
  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");
    if ((largeTextEnabled == "true") && !(isIE6 ))
    {
    newdiv.style.padding='0px 0px 5px';
    }

 
    newdiv.innerHTML = sepdiv + this.content[j].RenderPromo();
    
  
    ni.appendChild(newdiv);
  

    j = j +1;

  }
  
  var k = 0;
  
  while(k < i)
  {
     var newdiv = document.createElement('div');
     newdiv.setAttribute("class","pscroller4");
     if ((largeTextEnabled == "true") && !(isIE6 ))
     {
        newdiv.style.padding='0px 0px 5px';
     }
     newdiv.innerHTML = sepdiv + this.content[k].RenderPromo();
     ni.appendChild(newdiv);

     k = k +1;
  }
  
  if (DisplayViewAllPromo)
  {
  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)
    if (shrink > tickerinstance.tdHeight)
	{
	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 tickeriddiv = document.getElementById(tickerinstance.tickerid);
	tickeriddiv.style.height = tickerinstance.tdHeight + "px";
	
    var imgelem = document.getElementById("expandtable_"+tickerinstance.tickerid);
    imgelem.onclick = function(){tickerinstance.expandticker=1}

    var collelem =  document.getElementById("expandcoldiv_"+tickerinstance.tickerid);
    collelem.innerHTML = expandtext;

    var imgs = document.getElementById("imgdisplay_"+tickerinstance.tickerid);
    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].RenderPromo();
    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);

}
