﻿// ticker variables //
var infoTimer;
var tickerDiv;
var infoDiv;
var transLevel = 0;
var divWidth = 94;
var divMargin = 8;
var nextImg = 7;
var imgArray = new Array();
var lastAction; // on mouse over, the variable is set, so that in mouse out the last action is resumed.
function StartTicker()
{
    tickerDiv = document.getElementById('ticker');
    if(!tickerDiv) return;
    
    var children = document.getElementById('divJust').childNodes;
    var j = 0; 
    for (var i=0; i<children.length; i++)
    {
        if(children[i].nodeType == 1)
        {
            var img = children[i];
            if(j<6)
                tickerDiv.childNodes[j].appendChild(img);
            imgArray[j] = img;
            j++;
        }
    }
    BeginShiftLeft();
}
function BeginFadeIn()
{
    lastAction = 0;
    infoDiv = tickerDiv.lastChild;
    infoTimer = setTimeout("FadeIn()", 100);            
}
function BeginShiftLeft()
{
    lastAction = 1;            
    infoDiv = tickerDiv.firstChild;
    infoTimer = setTimeout("ShiftLeft()", 2000);            
}
function FadeIn()
{
    if(transLevel < 100)
    {
        transLevel++;
        infoDiv.style.filter = 'alpha(opacity=' + transLevel + ')';
        infoDiv.style.opacity = transLevel / 100;
        infoDiv.style.MozOpacity = transLevel / 100;
        infoTimer = setTimeout("FadeIn()", 20);
    }
    else
    {
        clearTimeout(infoTimer);
        BeginShiftLeft();
    }
}
function ShiftLeft()
{
    if(divWidth > 0)
    {
        infoDiv.style.width = divWidth - 2 + 'px';
        divWidth = divWidth - 2;
        infoTimer = setTimeout("ShiftLeft()", 20);
    }
    else
    {
        if(divMargin > 0)
        {
            infoDiv.style.margin = divMargin - 1 + 'px';
            divMargin = divMargin - 1;
            infoTimer = setTimeout("ShiftLeft()", 20);
        }
        else
        {
            infoDiv.style.filter = 'alpha(opacity=0)';
            infoDiv.style.opacity = 0;
            infoDiv.style.MozOpacity = 0;
            infoDiv.style.width = '94px';
            infoDiv.style.margin = '8px';
            InitTickerVar();
            tickerDiv.removeChild(infoDiv);
            tickerDiv.appendChild(infoDiv);
            SetNewImage();
            clearTimeout(infoTimer);            
            BeginFadeIn();
        }
    }
}
function SetNewImage()
{
    while (infoDiv.hasChildNodes())
    {
      infoDiv.removeChild(infoDiv.firstChild);
    }
    infoDiv.appendChild(imgArray[nextImg]);
    nextImg = (nextImg + 1) % 10;
}
function InitTickerVar()
{
    divWidth = 94;
    divMargin = 8;
    transLevel = 0;
}
function HaltTicker()
{
    if(lastAction == 0)
    {
        infoDiv.style.filter = 'alpha(opacity=100)';
        infoDiv.style.opacity = 1;
        infoDiv.style.MozOpacity = 1;
    }
    clearTimeout(infoTimer);
}
function ResumeTicker()
{
    if(tickerDiv)
        BeginShiftLeft();            
}

