// Algorithms		
var algorithms = {
	'111': "Silverstar",
	'011': "Silverstar",
	'010': "Silverstar",
	'101': "Coolblue",
	'001': "Coolblue",
	'110': "Ultralife",
	'100': "Ultralife",
	'000': "Ultralife"
};

var viewAllLink = '#actions .right #view-all',
    allBulbs = 'div.bulbs';

$(document).ready(function() {

	$(viewAllLink).click(function(e) {
		e.preventDefault();
		tc_log('aftersales_lightbulb_viewbulbs');

		$(this).addClass('js-hide');

		// Show form Button and all bulbs
		showFindDealer();
		$(allBulbs).removeClass('js-hide');
	});

	$('input:radio').click(onRadioChange);

	$('#actions.btnForm .right a.find-dealer').click(function() {
		tc_log('aftersales_lightbulb_findyourdealer');
	});
});

function onRadioChange() {
	// Show next Radio Button
	var nextRow = $(this).parents('tr').next('tr');

	if (nextRow.length && nextRow.hasClass('js-hide')) nextRow.removeClass('js-hide');

	/* Check how many radio are selected and if all 3 then
	run function to see bulb */
	var key = '',
      radios = $('input:radio:checked');

	if (radios.length === 3) {
		radios.each(function() {
			key += this.value;
		});

		// Show form Button
		showFindDealer();
		$(viewAllLink).removeClass('js-hide');

		// Call function and pass algorithms[key] as arguement
		showBulb(algorithms[key]);
	}
}

function showBulb(algorithm) {
	var bulbId = $('#' + algorithm);
	if (!bulbId.hasClass('js-show')) {
		$(allBulbs).addClass('js-hide').removeClass('js-show');
		bulbId.removeClass('js-hide').addClass('js-show');
	}
}

function showFindDealer() {
	$('#actions.btnForm .right a.find-dealer').removeClass('js-hide');
}