
$(document).ready(function () { 

	function fix_my_widths (object) {
		max_per_line = 7;
		// --- num logos
		children_size = object.children().length;
		
		// -- find max factor
		if (children_size>=7){
			
			num_rows = Math.ceil(	children_size / 7 );
			num_per_row = Math.ceil(	children_size / num_rows  );
			max_per_line = num_per_row;
			
		} else {
			max_per_line = Math.ceil(children_size);
		}
	
		//---calc num of logos per line	
		if (jQuery.support.boxModel) {
		
			 width_of_container = 976;
			 
		} else {
		
			 width_of_container = 973;
			 
		}
		
		//alert( width_of_container);
		
		width_i = Math.floor(width_of_container/max_per_line);
		
		group_count = 1;
		processed_children = 0;
		recalced = 0;
		
		object.children().each(
		
			function( intIndex ){
				$(this).css("width", width_i + "px");
				$($(this).children()[0]).css("width", (width_i-10) + "px");
				processed_children++;
					if (group_count<max_per_line) {
					   group_count++;
					} else {
					  group_count = 1;
					}    
					
					rem_i = children_size % max_per_line;
				
					if ( (children_size-processed_children <= rem_i) && !recalced && rem_i) {					
						max_per_line = children_size-processed_children;
						width_i = Math.floor(width_of_container/max_per_line);
						recalced=1;
					} 
			}
		);
	}
   $(".lego20_976_adaptive_logobar").each(
		function( intIndex ){
		fix_my_widths($(this));
		}
   );
} );

