jQuery(document).ready( function() {
	mfrsHide('table.manufacturers');
});

function mfrsHide(s) {
	var $s = jQuery(s);
	
	var visible = 5;
	var showText = 'Показать все';
	var hideText = 'Спрятать лишние';
	
	if ( $s.length ) {
		var $lists = $s.find('ul');
		
		$lists.each( function() {
			if ( jQuery(this).children('li:not(.name)').length > 5 ) {
				jQuery(this).children('li:not(.name):not(:lt(' + visible + '))').hide();
			
				jQuery(this).parent().append('<p class="mfrs"><a href="#" class="mfrs-show">' + showText + '</a></p>');
			}
		});
		
		jQuery('a.mfrs-show').click( function() {
			var $list = jQuery(this).parent().siblings('ul');
		
			if ( jQuery(this).text() == showText ) {
				$list.children('li:hidden').show();
				jQuery(this).text( hideText );
			} else { 
				$list.children('li:not(.name):not(:lt(' + visible + '))').hide();
				jQuery(this).text( showText );
			}
			
			return false;
		});
	}
}

