$(document).ready(function() {

	//Select first module and activities on page load
	$('#modules li#1').addClass('selected');
	$('.activities li').each(function() {
		//Get id of current activity list item
		var activityId = $("input", this).attr('id') + '';
		if (activityId.indexOf('1_') >= 0) {
			$(this).css('display', 'block');
		} else {
			$(this).css('display', 'none');
		}
	});

	//Module list hover effect
	$('#modules li').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

	//Module list selection actions
	$('#modules li').not('#modules li li').click(function() {
		$('#all').attr('checked', '');
		var moduleId = $(this).attr('id');
		switch (moduleId) {
			case '1':
				$('.activities-title').text('Transport and Accommodation')
				break;
			case '2':
				$('.activities-title').text('Course Choices')
				break;
			case '3':
				$('.activities-title').text('Financial Support & Money Management')
				break;
			case '4':
				$('.activities-title').text('Out of hours (Part-time work and Socialising)')
				break;
			case '5':
				$('.activities-title').text('Future Plans')
				break;
		}
		$('#modules li').not(this).removeClass('selected');
		$(this).toggleClass('selected');
		$('.activities li').each(function() {
			//Get id of current activity list item
			var activityId = $("input", this).attr('id') + '';
			if (activityId.indexOf(moduleId + '_') >= 0) {
				$(this).css('display', 'block');
			} else {
				$(this).css('display', 'none');
			}
		});
	});


	$('#all').click(function() {
		var allStatus = $('#all:checked').val() + '';
		if (allStatus == 'on') {
			$('.activities li').each(function() {
				if ($(this).css('display') != 'none') {
					$('input.activity', this).attr('checked', 'checked')
				}
			});
		} else {
			$('.activities li').each(function() {
				if ($(this).css('display') != 'none') {
					$('input.activity', this).attr('checked', '')
				}
			});
		}
	});


	$('#modules li:first').addClass('first');
	$('.activities li:first').addClass('first');
});