
(function($){
    $.fn.Reactions = function() {
        var resp = 0;
        var self = $(this);
        var reacts;
        
        function shownext() {
            self.fadeTo('slow',0,function(){
                var msg = reacts.list.item[resp].message;
                var city = reacts.list.item[resp].city;
                var author = reacts.list.item[resp].author
                
                resp++;
                
                self.html(
                    '&bdquo;' + msg + '&ldquo;' + (author ? '<br/><i>' + (author ? author + (city ? ', ' + city : '') + '</i>' : '') : '')
                );
                    
                resp%=reacts.list.size;
                self.fadeTo('slow',1);
                setTimeout(shownext,5000);
            });
        }
        
        function reload() {
            $.ajax({
                url: "/ajax/napsali-nam/",
                data: {
                    view: "JSON",
                    reaction: -1
                },
                dataType: 'json',
                success: function(obj) {
                    reacts = obj;
                    shownext();
                }
            });
        }
        
        reload();

    };
})(jQuery);

