﻿var qtdNot = null;
var idxNot = 0;
var noticias = null;
var oStatus = "play";
$(document).ready(
    function() {
        try {
            $.ajax({

                type: "GET",
                url: cfg_URL + "/web/noticiasRss.aspx",
                dataType: "xml",
                success: function(xml) { lista(xml) }

            });
        } catch (e) { }
        $("#btnNotPrev").click(prevNot);
        $("#btnNotProx").click(nextNot);
        $("#btnNotPause").click(togleStatus);
    });
function lista(xml) {
    noticias = $("noticia", xml);
    qtdNot = noticias.length -1;
    getNot(1);
    window.setInterval("rotearNoticia()", "6000");
}
function getNot(idx) {
    $("#noticaP_tema").html($(noticias[idx]).find("tema").text());
    $("#noticaP_titulo").html("<a class='noticia-principal-roteador-link' href='" + $(noticias[idx]).find("url").text() + "'>" + $(noticias[idx]).find("titulo").text() + "</a>");
    $("#noticaP_img").attr("src",  $(noticias[idx]).find("imagem").text());
    $("#noticaP_link").attr("href", $(noticias[idx]).find("url").text());
}
function rotearNoticia() {
    if (oStatus == "play") {
        getNot(idxNot);

        if (idxNot == qtdNot)
            idxNot = 0;
        else
            idxNot += 1;
    }
}
function nextNot() {
    if (idxNot == qtdNot)
        idxNot = 0;
    else
        idxNot += 1;

    getNot(idxNot);
    pause();
}
function prevNot() {
    if (idxNot == 0)
        idxNot = qtdNot;
    else
        idxNot -= 1;

    getNot(idxNot);
    pause();
}
function pause() {
    oStatus = "play";
    togleStatus();
}
function togleStatus() {

    if (oStatus == "play") {
        $("#btnNotPause").attr("src", "../img/btNotPlay.gif");
        oStatus = "stop";
    } else {
         $("#btnNotPause").attr("src", "../img/btNotPause.gif");
         oStatus = "play";
     }
 }