// Reduces the length of admissions site feeds to a maximum number of items,
// and displays a "More..." link to reveal the rest.
// 
// Author: Eric Naeseth

// How many items should the shortened feed be reduced to?
// (this can also be set by adding a "count" attribute to the feed ul)
var SHORTENED_FEED_MAX_LENGTH = 12;

jQuery(function shorten_feeds($) {
	$('ul.feed').each(function shorten_feed() {
		var me = $(this);
		var items = me.children("li");
		if (me.attr("count")) { SHORTENED_FEED_MAX_LENGTH = parseInt(me.attr("count")); }
		
		if (items.length < SHORTENED_FEED_MAX_LENGTH + 2) {
			// Don't hide any items unless we have at least two to hide.
			return;
		}
		
		var insignificant = items.slice(SHORTENED_FEED_MAX_LENGTH);
		var expand = $('<a class="expand" href="#">More&hellip;</a>');
		expand.click(function expand_shortened_feed(e) {
			insignificant.show('fast');
			$(e.target).remove();
			return false;
		});
		
		me.after(expand);
		insignificant.hide();
	});
});

