(function ($) {
	$.fn.newspaper = function (tag_name, column_count) {
		var element = $(this), old_list = $(tag_name, element), new_list = $(old_list);

		var limit = old_list.size();
		for (var i = 0, j = 0, k = 1; i < limit; i++) {
			if (j >= limit) { j = k; k++; }
			new_list[j] = old_list[i].cloneNode(true);
			j = j + column_count;
		}
		element.empty();
		for (var i = 0; i < limit; i++) { element.append(new_list[i]); }

		return element;
	};
} (jQuery));

jQuery(function($) {
	$('.condensed ul').each(function () {
		$('li:gt(3)', this).hide(); /* :gt() is zero-indexed */
		$('li:nth-child(4)', this).after('<li>&nbsp;</li><li class="more"><a href="../news/"><strong>More News</strong></a></li>'); /* :nth-child() is one-indexed */
	});

	$('li.more a').on('click', function() {
		var li = $(this).parents('li:first');
		li.parent().children().show();
		li.remove();
		return false;
	});
	
	// stop the Lawyers menu item being clicked
	$('.menu .lawyers > a').attr('href', '#header').click(false);
	$('.menu .sectors > a').attr('href', '#header').click(false);
	$('.menu .practice-areas > a').attr('href', '#header').click(false);

	// turn the necessary lists into columns
	$('.menu .lawyers > ul').newspaper('li', 5);
	$('.menu .sectors > ul').newspaper('li', 2);
	
	new SWFObject('../_swf/logo.swf', 'logo-white', '232', '71', '9', '#000000').write('logo');
});


