﻿$(document).ready(function () {
    ShowNewsMarquee();
});

function ShowNewsMarquee() {
    var _xhr = $.post(Action("News","GetRecentNews"),
    { Count: 5 },
    function (res) {
        if (res.Error) alert(res.Error);
        else {
            $("#marquee-news-container").html('<marquee scrollamount="1" direction="left" loop="1" behavior="scroll"></marquee>');
            var s = "<table><tr>";
            for (var i = 0; i < res.News.length; i++) {
                var _color = isNaN(parseInt(res.News[i].Important)) ? "#dddddd" : parseInt(res.News[i].Important) == 0 ? "#dddddd" : "#ff5555";
                s += "<td><div style='margin-left:10px;background-color:" + _color + ";width:10px;height:10px'></div></td><td style='white-space:nowrap'><a target='_blank' style='text-decoration:none;font-size:11px;color:#764700;font-weight:bold' href='" + res.News[i].Url + "'>" + res.News[i].Title + "</a></td> ";
            }
            s += "</tr></table>";
            $("#marquee-news-container marquee").append(s);
            $('#marquee-news-container marquee').marquee('pointer').mouseover(function () {
                $(this).trigger('stop');
            }).mouseout(function () {
                $(this).trigger('start');
            })
            .bind("end", function () { ShowNewsMarquee(); });
            ;
        }
    });
    XHRS.push(_xhr);
}
