﻿; (function($) {
    $.fn.ticker = function() {
        return this.each(function() {
            var $this = $(this);
            var key = $this.attr("key");
            var interval = $this.attr("interval");
            var elm = this;

            getTickerHtml(key, elm);

            if (interval > 0) {
                setInterval(function() { getTickerHtml(key, elm); }, interval);
            }
        });
    };

    function getTickerHtml(key, elm) {
        TVBca.UI.Services.TickerService.GetTickerHtml(key,
        function(html) {
            updateElement(html, elm);
        },
        function(error) {
            updateElement("[An error has occurred]", elm);
            //alert("An error has occurred: " + error._message);
        });
    }

    function updateElement(html, elm) {
        $(elm).empty().append(html).parent().effect("highlight", {}, 3000);
    };

})(jQuery);

$(document).ready(function() {
    $(".ticker").ticker();
});