// Control de noticias
// Autor: Esteban D'Annunzio - Abr.2007

function Noticias(solapas, solapaActiva) {
    this.solapas = solapas;
    this.solapaActiva = solapaActiva;
    this.idTema = solapas[solapaActiva];
}

Noticias.prototype.selectTab = function(selectedElement, selectedName) {
    // Registrar solapa activa
    this.solapaActiva = selectedName;
    this.idTema = this.solapas[selectedName];

    // Cambiar estilo de solapa seleccionada
    var liNode = document.getElementById("NoticiasSolapas").firstChild;
    while (liNode) {
        liNode.className = "";
        liNode = liNode.nextSibling;
    }
    selectedElement.parentNode.className = "Selected";
}

Noticias.prototype.mostrarPopup = function (el, idNoticia) {

    var url = jQuery(el).attr("href") + "?referer=principal";

    Helper.CookieNotiLeidas(idNoticia);

    ticker1.stop();

    // Abrir noticia
    jQuery("#PopUpDiv").dialogPlugin({
        width: 700,
        height: 480,
        minWidth: 495,
        minHeight: 287,
        title: "Nosis - NyM - Noticias",
        intBgColorIframe: "#525F72",
        intTieneIframe: true,
        intSrcIframe: url,
        close: function (event, ui) { limpiarPopupNoticia(); }
    });
    jQuery("#PopUpDiv").dialogPlugin("fn", "open");

    return false;
}

Noticias.prototype.irANyMnet = function() {
    switch (this.solapaActiva) {
        case "lnkEconomicas":
            window.location.href = "SitioNyMnet/Noticias.aspx?categoria=economica"
            break;
        case "lnkPoliticas":
            window.location.href = "SitioNyMnet/Noticias.aspx?categoria=politica"
            break;
        case "lnkAgropecuarias":
            window.location.href = "SitioNyMnet/Noticias.aspx?categoria=agropecuaria"
            break;
        case "lnkEmpresariales":
            window.location.href = "SitioNyMnet/Noticias.aspx?categoria=empresarial"
            break;
    }
}

function limpiarPopupNoticia(e) {
    ticker1.start();
    jQuery('#PopUpDiv').find("iframe").attr("src", "about:blank");
    jQuery('#PopUpDiv').dialogPlugin("fn", 'destroy');
}

jQuery(function () {

    jQuery("#ListadoNoticiasContenedor").delegate(".divNoticia a", "click", function (event) {

        event.stopPropagation();

        var parentClasses = jQuery(this).parent().attr("class"),
            id = parentClasses.substr(parentClasses.indexOf("codigos")).split("_")[1];

        jQuery.referenciaInstancia.mostrarPopup(jQuery(this), id);

        return false;

    });

});
