/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function tabularize(container_sel, col_count, fill)
{
  if(!col_count) col_count = 4;

  var row, col;
  var container = $(container_sel);
  var items = $.makeArray(container.children('li').remove());
  var itemsCount = items.length;

  container.addClass('tabularized');

  for(row = 0; row<Math.ceil(itemsCount/col_count);row++)
  {
    var rowElement = $('<li class="row"><ul></ul></li>');
    if(row == Math.ceil(itemsCount/col_count)-1) rowElement.addClass('last');
    for(col=0;col<col_count;col++)
    {
      if(items.length)
      {
        var item = items.shift();
        rowElement.children('ul').append(item);
      } else if (fill) {
        var item = $('<li>&nbsp;</li>');
        rowElement.children('ul').append(item);
      } else break;
    }
    container.append(rowElement);
  }
  
}
