// Newsticker do ultimo segundo
// Desenvolvido por Luis Henrique Cassis Fagundes <lhfagund@ig.com.br>

childcount = -1;
inicializado = 0;
mudando = 1;
posicao_fora = Math.ceil(height2/10)*10;
var noticias;
canais = escape(canais);



function init() {

    child = new DynLayer('childDiv','mainDiv');
    child.slideInit();

    DynLayerInit();
    results.load = DynLayerLoad;

    setTimeout("noticiasReload();",1)
}

function continua(anda) {
    mudando = 1;
}

function para() {
    mudando = 0;
}

function noticiasInit(vetor) {
    noticias = vetor;
    if (!inicializado) {
        inicializado = 1;
        child.hide();
        Muda();
    }
}

function proxima() {
    childcount = (childcount + 1) % noticias.length;
    return noticias[childcount];
}

function anda() {
    setTimeout("Muda()",5000);
}

function Muda() {
    if (mudando) {
        para();
        child.slideTo(0,posicao_fora,10,20,"child.write(proxima()); child.show(); child.slideTo(0,0,10,20,'continua();anda()')");
    }
    else {
        setTimeout("Muda()",1000);
    }
}

function noticiasReload() {


    var numero="";
    var h = 0;

 if (canais.indexOf("saude") != -1){
            if(h==0){
                    numero+=237;
                    h=1;
                }
                else{
                numero+="-"+237;
                }
        }


 if (canais.indexOf("bem") != -1){
            if(h==0){
                    numero+=237;
                    h=1;
                }
                else{
                numero+="-"+237;
                }
        }

    if (canais.indexOf("cultura") != -1){
            if(h==0){
                    numero+=37;
                    h=1;
                }
                else{
                numero+="-"+37;
                }
        }

    if (canais.indexOf("dinheiro") != -1){
            if(h==0){
                    numero+=34;
                    h=1;
                }
                else{
                numero+="-"+34;
                }
        }

    if (canais.indexOf("esportes") != -1){
            if(h==0){
                    numero+=35;
                    h=1;
                }
                else{
                numero+="-"+35;
                }
        }

    if (canais.indexOf("futebol") != -1){

        }

    if (canais.indexOf("noticias") != -1){
            if(h==0){
                    numero+=32;
                    h=1;
                }
                else{
                numero+="-"+32;
                }
        }

    if (canais.indexOf("mundo") != -1){
            if(h==0){
                    numero+=38;
                    h=1;
                }
                else{
                numero+="-"+38;
                }
        }

    if (canais.indexOf("sinopses") != -1){

        }

    if (canais.indexOf("noticmundo") != -1){
            if(h==0){
                    numero+=33;
                    h=1;
                }
                else{
                numero+="-"+33;
                }
        }

    if (canais.indexOf("cartas") != -1){

        }

    if (canais.indexOf("vestibular") != -1){
            if(h==0){
                    numero+=39;
                    h=1;
                }
                else{
                numero+="-"+39;
                }
        }

   if (canais.indexOf("odia") != -1){
            if(h==0){
                    numero+=42;
                    h=1;
                }
                else{
                numero+="-"+42;
                }
        }

        if (canais.indexOf("todos") != -1){

                    numero="32-33-34-35-237-37-38-39-42";

        }


    //results.load('http://www.ig.com.br/home/channels/news_ticker/0,1601,'+canais+',00.html');



    results.load('http://ultimosegundo.ig.com.br/home/lista_noticias_usflashwebmaster/0,,'+numero+',00.html');


    setTimeout("noticiasReload()",120000);
}

init();
