var byo_current_choice = '';



var byo_base_url = 'http://doorstorecambridge.com/byo_desk.php';



$(function()

{

	// Hide all main images and button images

	$('.byo_main_image').hide();

	

	// Remove the image loading class

	$('.byo_main_image').removeClass('byo_hide_image');

	$('.cs_button').removeClass('byo_hide_image');

	

	// On a change in a radio button

	$('.byo_radio').change(function(e)

	{	

		var this_id = $(this).attr('id');

	

		// Call the helper

		show_item(this_id);

	}

	);

	

	

	// On a click on the 'next' button

	$('#byo_next').click(function(e)

	{

		set_up_next();

	}

	);

	

	// Click on back button

	$('#byo_back').click(function(e)

	{

		window.location.href = byo_base_url + byo_go_back_args;

	}

	);

	

	// On click on restart button

	$('#byo_restart').click(function(e)

	{

		window.location.href = byo_base_url;

	}

	);

	

	// TESTING!

//	$('#cs_1').val('some_value');



	// This will check the button (no change event, however)

//	$('#cs_1').attr('checked', 'checked');



	// If a current choice is present

	if(byo_current_choice != '')

	{

		// Show the choice

		show_item(byo_current_choice);

		

		// Check the radio button

		$('#' + byo_current_choice).attr('checked', 'checked');

	}

	

});







function show_item(item_id)

{

	// Fade out all main images shown

	$('.main_shown').fadeOut('fast');



	// Store selection

	byo_current_choice = item_id;



	// Remove 'shown' class

	$('.main_shown').removeClass('main_shown');

	

	// Make class name for the main images to show

	var class_name = '.' + item_id + '_image';

	

	// Mark images to be shown so they can be found later

	$(class_name).addClass('main_shown');

	

	// Display the images

	$('.main_shown').fadeIn('fast');

	

	// Fade in the button

// 	var button_id = '#' + item_id + '_button';

// 	$(button_id).fadeIn('fast');

}







function set_up_next()

{

	// If no choice has been made

	if(byo_current_choice == '')

	{

		alert('Please make a selection.');

		return;

	}

	

	// Figure out which choice was selected

	var i = 0;

	while(byo_choice_ids[i] != byo_current_choice)

	{

		i++;

	}



	// Just for the demo

// 	if(i != 2 && byo_current_step == 'A1')

// 	{

// 		alert('Only the wing desk is available for now.');

// 		return;

// 	}

	

	// Put together the GET string for the new request

	var GET = '';

	GET += byo_base_ps_string + byo_current_step + ',' + i;

	GET += '&cs=' + byo_destinations[i];

	

	// Go to the next step

	window.location.href = byo_base_url + '?' + GET;

}


