function tag_check_selection() {
	if (this.checked) {
		$(this).parent('li').addClass('selected');
	} else {
		$(this).parent('li').removeClass('selected');
		$(this).parent('li').find('li input').each(function() { this.checked = false; });
		$(this).parent('li').find('li input').each(tag_check_selection);
	}
}
$(document).ready(function() {
	$('.tags li input').each(tag_check_selection);
	$('.tags li input').click(tag_check_selection);
    $('#sidebar-nav').append('<ul class="tag-cloud"></ul>');
	$('.taxonomy li').click(function() {
		var this_rel = $(this).attr('rel');
		if (this_rel=='all') {
			if (!$(this).hasClass('selected')) {
				$('.taxonomy li').removeClass('selected');
				$(this).addClass('selected');
			}
		} else {
			if ($(this).hasClass('selected')) {
				$(this).removeClass('selected');
				if ($('.taxonomy li.selected').size()==0) {
					$('.taxonomy li[rel=all]').addClass('selected');
				}
			} else {
				$(this).addClass('selected');
				$('.taxonomy li[rel=all]').removeClass('selected');
			}
			//$('#sidebar-nav .tag-cloud').append('<li rel="'+this_rel+'">'+$(this).html()+'</li>');
		}
		if ($('#aims-question-list').size()>0) {
			$('#aims-question-list li').hide();
			var found = false;
			$('.taxonomy li.selected').each(function() {
				var this_rel = $(this).attr('rel');
				if (this_rel!='all') {
					$('#aims-question-list li.'+this_rel).show();
					if ($('#aims-question-list li.'+this_rel).size()>0) found = true;
					$(this).children('a').html();
				} else {
					$('#aims-question-list li').show();
					found = true;
				}
			});
			if (!found) {
				$('.entry #purpose h1').html('No Questions in this Category');
				$('.entry #purpose h1').css('backgroundColor','#ff0000');
			} else {
				$('.entry #purpose h1').html('Most Recent Entries');
				$('.entry #purpose h1').css('backgroundColor','#511A82');
			}
			return false;
		}
	});
	$('#nav a').each(function() {
		$(this).click(function() { return false; });
	});
	$('#purpose a:first').click(function() { alert('This feature has not yet been implemented.'); return false; });
});