// Function to shuffle arrays.
Array.prototype.shuffle = function() {
	var s = [];
	while (this.length) s.push(this.splice(Math.random() * this.length, 1));
	while (s.length) this.push(s.pop());
	return this;
}

// Function to make mirror names "bold" when checked.

function MirrorFontSwitch () {
	$('.mirror:checked').each(function() {
		$(this).parent('label').next().css('font-weight', 'bold');
	});
	$('.mirror').not(':checked').each(function() {
		$(this).parent('label').next().css('font-weight', 'normal');
	});
}

$(document).ready(function($) {
	MirrorFontSwitch ();
});


/*
function RecommendSelectMirrors(that) {

	// Ensure the Random checkbox isn't checked.
	$('#random').attr('checked', false);
	
	// Exceute main part.
	if ($(that).attr('checked')) {

		// Uncheck all checkboxes first.
		$('.mirror').each(function() {
			$(this).attr('checked', false);
		});
		
		// The list of recommended mirrors.
		var listRecommend = new Array(1,2,3,4,5);
	
		for(var i = 0; i < listRecommend.length; i++) {
			$('[class="mirror ' + listRecommend[i] + '"]').attr('checked', true);
		}
		
	} else {
		// Uncheck all checkboxes.
		$('.mirror').each(function() {
			$(this).attr('checked', false);
		});
	}
		
}
*/

function RandomSelectMirrors(that) {

	// Ensure the Recommended checkbox isn't checked.
	$('#recommend').attr('checked', false);

	// Exceute main part.
	if ($(that).attr('checked')) {
	
		// Uncheck all checkboxes first.
		$('.mirror').each(function() {
			$(this).attr('checked', false);
		});
		
		// Amount of mirrors.
		var listRandom = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18);
		listRandom.shuffle();
	
		for(var i = 0; i < 5; i++) {
			$('[class="mirror ' + listRandom[i] + '"]').attr('checked', true);
		}
		
	} else {
		// Uncheck all checkboxes.
		$('.mirror').each(function() {
			$(this).attr('checked', false);
		});
	}
	
	MirrorFontSwitch ();
	
}
