/**
*	javascript functions for «Garden-Best» (http://garden-best.ru).
*
*	version:		1.0
*	date:				12.03.2011
*	author:   	DelphinPRO
*	email:			delphinpro@profcoding.ru
*	website:		http://profcoding.ru/
*/

function CalculateFrontCatalog(){
	var total = $('#frontCat > .fcItem').size();
	if (total > 0){
		container_width = $('#frontCat').width();
		item_count = Math.floor(container_width / 166);
		item_width = Math.floor(container_width / item_count) - 1;
		item_last_row = Math.floor(total / item_count) * item_count - 1;
		$('#frontCat .fcItem').removeClass('norb nobb').width(item_width).filter(function(i){
			if (((i+1) % item_count) == 0) {
				$(this).addClass('norb');
			}
		});
		$('#frontCat .fcItem:gt('+item_last_row+')').addClass('nobb');
		
		var max_height = 0;
		$('#frontCat > .fcItem .fcImg').each(function(){
			var height = $(this).height();
      if(height > max_height)
        max_height = height;
		});
		$('#frontCat > .fcItem .fcImg').height(max_height);

		max_height = 0;
		$('#frontCat > .fcItem > .fcCalc').each(function(){
			var height = $(this).height();
      if(height > max_height)
        max_height = height;
		});
		$('#frontCat > .fcItem').css({'height':'auto'});
		$('#frontCat > .fcItem > .fcCalc').height(max_height);
		/*$('#debug').html('<br/>container_width - '+container_width);
		$('#debug').append('<br/>item_count - '+container_width / 166);
		$('#debug').append('<br/>item_count - '+item_count);
		$('#debug').append('<br/>item_width - '+item_width);
		$('#debug').append('<br/>item_last_row - '+item_last_row);*/
	}
}

$(document).ready(function(){
	CalculateFrontCatalog();
	$(window).resize(function(){
		CalculateFrontCatalog();
	});
});


