/**
 * jQuery PaintChat Plugin
 *
 * Used to do various tasks related with PaintChat
 *
 * @author      Flash
 * @created     2010/02/22
 * @website     http://www.mangamasters.com/
 */

jQuery(function($){

    jQuery.fn.pchatUserList = function() {
        return this.each(function(){
            var obj = $(this);
            var id = obj.attr('id');
            obj.addClass('loading');

            jQuery.ajax({
                cache: true,
                type: 'GET',
                url: '/ajax/lobby?room='+id,
                dataType: 'json',
                param: {room: id},
                success: function(data){
                    $(obj).removeClass('loading');
                    $(obj).empty(); // Clear the lobby for population

                    var n = 0;
                    $.each(data, function(i, item){
                        rowClass = (n % 2 == 0) ? 'row1' : 'row2';
                        jQuery('<div>')
                            .html(item)
                            .appendTo(obj)
                            .addClass(rowClass);
                        n++;
                    });
                },
                error: function(){
                    $(obj).removeClass('loading');
                    $(obj).html( $('<div>').html('<strong>Empty</strong>').addClass('row1') );
                }
            });
        });
    };

});