function collapse_subnav (nav_id, photo_id) {
	var i = 0,
		nodes = [],
		removed = [],
		list,
		max,
		container,
		more_li,
		more_ul,
		more_span;
	$('#'+nav_id+' li').each(function () {
		nodes.push(this);
	});
	
	max = $('#'+photo_id).height();
	container = $('#'+nav_id);
	list = $('#'+nav_id+' ul');
	
	if (container.height() > max) {
		more_span = $('<span>more...<\/span>').css({cursor: 'pointer'});
		more_li = $('<li><\/li>');
		more_ul = $('<ul><\/ul>');
		more_li.append(more_span);
		more_li.append(more_ul);
		list.append(more_li);
		
		// Pull them out.
		i = nodes.length - 1;
		do {
			nodes[i].parentNode.removeChild(nodes[i]);
			removed.push(nodes[i]);
			i -= 1;
		} while (i >= 1 && container.height() > max);
		
		// Put them back in.
		for (i = removed.length - 1; i >= 0; i -= 1) {
			more_ul.append(removed[i]);
		}
	}
}

// Make the top-level nav nodes clickable on their LI elements,
// except inside their UL subnavs.
$(function () {
	var inner = false,
		nav = $('#site-nav')[0];
	
	$('#site-nav ul li ul').click(function () {
		inner = true;
	});
	$('#site-nav ul li a').each(function () {
		var a = this;
		if (a.parentNode.parentNode.parentNode === nav) {
			$(a.parentNode).click(function () {
				if (!inner) {
					location.href = a.href;
				}
				inner = false;
			});
		}
	});
});

