var pauseMarquee=5000;
var up = 1;
var heightIt = 15;
var incAux = 1;

var copyspeed=1;
var newsHeight=0;
var liTotalH=0;
var heightI, actualheight;
var cross_marqueeI;
var arrObj = new Array();
var lefttime=0;
var ativo = false;
var inativo = false;

function Next()
{
	if (inativo == false)
	{
		Para();
		switch(up)
		{
			case 1:
			{
				Sobe();
				break;
			}
			case 0:
			{
				Desce();
				break;
			}
		}	
	}
}
/*function Previous()
{
    Para();
    switch(up)
    {
        case 1:
        {
            Desce();
            //Para();
            break;
        }
        case 0:
        {
            Sobe();
            //Para();
            break;
        }
    }
}*/
function Sobe()
{
    UpDown(1); 
    if(!ativo) 
    {
        ativo = true;
        lefttime = setInterval('scrollmarquee();',40);
    }
}
function Desce()
{
    UpDown(0);
    if(!ativo) 
    {
        ativo = true;
        lefttime = setInterval('scrollmarquee();',40);
    }
}

function Inativar()
{
	var objImg = document.getElementById('imgControle');	
	
	if (inativo == false)
	{
		objImg.src = '/images/ti/elementos/ticker/play_ticker.gif';	
		clearTimeout(lefttime);  
		ativo = false;
		inativo = true;      	
	}
	else
	{
		objImg.src = '/images/ti/elementos/ticker/pause2_ticker.gif';
		ativo = true;
		lefttime = setInterval('scrollmarquee();',40);
		Continue();	
		inativo = false;
	}   
}

function Para()
{
	if (inativo == false)
	{
		clearTimeout(lefttime);  
		ativo = false;  	
	}
}
function Continue()
{
	if (inativo == false)
	{
		switch(up)
		{
			case 1:
			{
				Sobe();
				break;
			}
			case 0:
			{
				Desce();
				break;
			}
		}	
	}
}

function UpDown(param)//1 sobe , 0 desce
{
    up = param;
}

function scrollmarquee(){
    heightI = 0;
    actualheight = 0;
    for(i=0; i<arrObj.length;i++)
    {
        cross_marqueeI=arrObj[i];
        actualheight=parseInt(cross_marqueeI.obj.offsetHeight);
        heightI += actualheight;
        switch (up)
        {                
            case 1:
            {
                if (incAux <= heightIt)
                {
                    cross_marqueeI.style.top=parseInt(cross_marqueeI.style.top) - copyspeed+"px";
                    incAux++;
                }       
                else
                {
                    incAux = 1;
                    if (parseInt(cross_marqueeI.style.top) < (-1*liTotalH)+heightIt )
                    {
                        cross_marqueeI.style.top='0px';
                    }
                    Para();
                    lefttime = setTimeout("Sobe();",pauseMarquee);                    
                }                  
                break;
            }
            case 0:
            {
                if (incAux <= heightIt)
                {
                    cross_marqueeI.style.top=parseInt(cross_marqueeI.style.top) + copyspeed+"px";
                    incAux++;
                }
                else
                {
                    incAux = 1;
                    if (parseInt(cross_marqueeI.style.top)+ heightI > liTotalH)
                    {
                        cross_marqueeI.style.top='0px';
                    }
                    Para();
                    lefttime = setTimeout("Desce();",pauseMarquee);  
                }                
                break;
            }
        }//switch        
    }//for   
    cross_marqueeI = null;
}//scrollmarquee

function initializeTk(){

    var cross_marquee=new getObj("tkUl");
    newsHeight = cross_marquee.obj.offsetHeight;
    var cont=0;
    for(i=0;i<=cross_marquee.obj.childNodes.length;i++)
    {
        if (cross_marquee.obj.childNodes[i] != '[object Text]' && cross_marquee.obj.childNodes[i] != undefined)
        {
            arrObj[cont] = new getObj(cross_marquee.obj.childNodes[i].id);
            arrObj[cont].style.top = '0px';
            liTotalH += parseInt(arrObj[cont].obj.offsetHeight);            
            cont++;
        }
    }  
    cross_marquee = null;
    lefttime = setTimeout("Sobe();",pauseMarquee);
}

if (window.addEventListener)
    window.addEventListener("load", initializeTk, false);
else if (window.attachEvent)
    window.attachEvent("onload", initializeTk);
else if (document.getElementById)
    window.onload=initializeTk;