﻿/// <reference path="../API/Agility.js" />

Agility.RegisterNamespace("BNN.NewsBySectorArchive");

(function (NewsBySectorArchive) {

    NewsBySectorArchive.OnInit = function(p) {
        
        var client = $("#" + p.ClientID);

        $.ajax({
            url: AjaxWebserviceSvcUrl + "/GetNewsBySector?newsBySectorToShow=" + p.NewsBySectorToShow,
            contentType: "application/json",
            dataType: "json",
            success: function(jsonResponse) {
                
                if (jsonResponse != undefined && jsonResponse != null) {
                    
                    var html = "";
                    $.each(jsonResponse, function(i, newsBySector) {
                        $.each(newsBySector.Stories, function(ii, story) {
                            html += "<li><a href='" + story.Url + "'>" + story.Headline + "</a></li>";
                        });
                        $(html).insertAfter(client.find("li[data-id=" + newsBySector.Category.ContentID + "]"));
                        html = "";
                    });
                }
            }
        });
        
        renderTip();
    };

    function renderTip() {
        $(".archiveTip").tooltip({ effect: 'slide', position: 'bottom right', offset: [-20, 0] });
        $("ul.tabs").tabs("div.panes > div");
    };

})(BNN.NewsBySectorArchive);


