/* --- js/userlist.js -- start ------------------------------------- *
 * 
 * $Id: userlist.js 148 2010-07-23 12:46:34Z vugluskr $
 *
 * Require:
 *   jquery.js
 */

function ui_userlist() {
    this.list_blocks = $('.puzzle_users .list');
    this.wrapper = $('.puzzle_users *[bind="wrapper"]');
    if (! this.wrapper.length)
	throw Error('bind="wrapper" not found.');
    this.wrapper = this.wrapper[0];
    this.tout_id = null;

    this.blk_width = 220;
    this.blk_space = 2;
    this.blk_offs_l = 1;
    this.blk_offs_r = 1;

    ui_userlist.prototype.init_hndl = function() {
	var self = this;

	$(window).resize(function(){ self.hndl_resize(false); })
    }

    if (this.list_blocks.length)
	this.init_hndl();

    ui_userlist.prototype.hndl_resize = function(actual) {
	if (! actual) {
	    var self = this;
	    if (this.tout_id)
		clearTimeout(this.tout_id);
	    this.tout_id = setTimeout(function(){ self.hndl_resize(true); }, 100);

	    return;
	}
	
	var w = $(this.wrapper).width();
	var brd = this.blk_offs_l + this.blk_offs_r;
	var cnt = 1;
	var inc = this.blk_width + this.blk_space;
	var w2 = this.blk_width + brd;
	while (w2 + inc <= w)
	    w2 += inc;

	var idx;
	for (idx = 0; idx < this.list_blocks.length; idx++) {
	    $(this.list_blocks[idx]).css({width: w2 + 'px'});
	}

	this.tout_id = null;
    }
    this.hndl_resize(true);
}
/* --- js/userlist.js -- end --------------------------------------- */

