$(function() {
	
	// get current step
	if($('form#loans input[name="process_step"]').length) {
		var current_step = $('form#loans input[name="process_step"]').val();
	} else {
		var current_step = 0;
	}
	

	// set row class for steps 1 and 2
	if(current_step == 1 || current_step == 3) {
		$('#loans table tr td:even').addClass('settingDescriptions');
		$('#loans table tr td:odd').addClass('settingValues');
	}
	
	// step 1
	if(current_step == 1)
	{
		// load the sliders
		$('#tenure').selectToUISlider().hide();
		$('#margin_finance').selectToUISlider().hide();
		// $('#tenure').slider();
		// $('#margin_finance').slider();

		// start by hiding the extra setting rows
		$('ul#extra_purchase_settings').hide();
		$('ul#extra_refinance_settings').hide();

		// determine which setting rows to display
		var loan_purpose = $('input[name="loan_purpose"]:checked').val();
		
		if(loan_purpose == 1)
			$('ul#extra_purchase_settings').show();
		else if(loan_purpose == 2)
			$('ul#extra_refinance_settings').show();
			
		// display different setting rows if loan purpose is changes
		$('input[name="loan_purpose"]').click(function() {
			switch($(this).val()) {
				case '1':
					$('ul#extra_purchase_settings').show();
					$('ul#extra_refinance_settings').hide();
				break;

				case '2':
					$('ul#extra_refinance_settings').show();
					$('ul#extra_purchase_settings').hide();
				break;
			}
		});
	
		// first step was submitted
		$('form#loans').submit(function(event) {
			// get slider values
			var tenure = $('form#loans div#tenure a').css('left').replace('%', '');
			var margin_finance = $('form#loans div#margin_finance a').css('left').replace('%', '');

			// set hidden input slider values
			$('form#loans input[name="tenure_percentage"]').val(tenure);
			$('form#loans input[name="margin_finance_percentage"]').val(margin_finance);
		});
		
	} // end step 1
	
	if(current_step == 2) {
		// alternate row colors
		// $('form#loans table tr:even').css('background-color', '#eee');
		
		// hide package notes & less link
		$('form#loans table p.notes').hide();
		$('form#loans table a.lessNotes').hide();
		
		// show package notes
		$('a.moreNotes').click(function(event) {
			event.preventDefault();
			
			// hide the more link
			$(this).hide();
			
			// show the less link
			$(this).next('a.lessNotes').show();
			
			// show the notes
			$(this).nextAll('p.notes').show();
		});
		
		// hide package notes
		$('a.lessNotes').click(function(event) {
			event.preventDefault();
			
			// hide the less link
			$(this).hide();
			
			// show the more link
			$(this).prev('a.moreNotes').show();
			
			// hide the notes
			$(this).next('p.notes').hide();
		});
	}
});

