
var indexNoticia = null;
var speed1 = 200;

function initSlides(noticia,index){
    
    var index_noticia = parseInt(noticia);
    var index1 = parseInt(index);
    var index2 = index1 + 1;
    

    var obj1 = $('.span_noticias[index="'+index_noticia+'"] .imagem a[index="'+ index1 +'"]');
    var obj2 = $('.span_noticias[index="'+index_noticia+'"] .imagem a[index="'+ index2 +'"]');
    
    if( obj2.attr('index') && obj1.attr('index') ){
//        alert("vai SUMIR: "+index1);
        obj1.fadeTo(speed1, 0, function(){
            obj1.css('display','none');
//            alert("SUMIU: "+index1+" \nPROXIMO P APARECER: "+index2);
            var obj2 = $('.span_noticias[index="'+index_noticia+'"] .imagem a[index="'+(index2)+'"]');

            obj2.css('opacity','0');
            obj2.css('display','block');
            obj2.fadeTo(speed1,1,function(){
//                alert("APARECEU: "+index2);
                setTimeout( initSlides , 1000, index_noticia,index2);
            });
        });
    }else{
        alert("vai alterar a noticia: "+(index_noticia+1));
        setNoticia(index_noticia+1);
        return false;
    }
    return false;
}

function setNoticia(index_noticia){
//    alert("ALERT: "+index_noticia);
    indexNoticia = index_noticia;
    var display = $(".span_noticias[index='"+index_noticia+"']").css('display');

    if(display=='none'){
        $('.span_noticias').hide(speed1, function(){
            $(".span_noticias[index='"+index_noticia+"']").show(speed1,function(){
//                alert("setNoticia()");
                //initSlides(index_noticia,0);
            });
        });
    }else{
//        alert("setNoticia()");
//        initSlides(index_noticia,0);
    }
    return false;
}
