var firstpage;
var lastpage;
var legend;
var originalLegend;

jQuery(document).ready(function() {
	firstpage = jQuery('.survey_new .survey_question:lt(2)');
	lastpage = jQuery('.survey_new .survey_question:gt(1), .survey_new .survey_submission');
	legend = jQuery('.survey_new legend');
        return1 = jQuery('.survey_return1');
	lastpage.hide();
	firstpage.find('input:radio').bind('click', updateForm );
	jQuery('.survey_answer_special_button').bind('click', updateChoiceAndForm );
	originalLegend = legend.html();
	legend.html( originalLegend+' 1' );
	updateForm();
});

var updateChoiceAndForm = function() {
	jQuery('#survey_question_special_choice').val( this.id.substring( this.id.lastIndexOf('_') + 1 ) );
	updateForm();
};

var updateForm = function() {
	switch ( firstpage.find('input:checked').val() ) {
		case 1:
		case '1':
		case 2:
		case '2':
			jQuery('.survey_answer_special:first').hide();
			jQuery('.survey_answer_special:gt(0)').show();
			break;
		case 0:
		case '0':
            jQuery('.survey_answer_special').show();
			break;
		default:
			jQuery('.survey_answer_special').hide();
			break;
	}
	if (
		( firstpage.find('input:checked').size() >= 1 ) &&
		( jQuery('#survey_question_special_choice').val() )
	) {
		firstpage.hide();
		lastpage.show();
		jQuery('#survey_progress_bar_item_2').addClass('done');
		legend.html( originalLegend+' 2' );
        return1.show();
        jQuery('.survey_participation_title').html( alternative_survey_title );
	}
};