(function($) {
	
	/**
	 * "Select the user role(s) for which to enable the subaccount system" setting.
	 */
	 
	// Initialize Selectize.
	$("#sfwc_option_selected_roles").selectize({
		placeholder: 'Select role...',
		plugins:
		[
			"remove_button",
		]
	});
	
	
	/**
	 * "New Subaccount Default Role" setting.
	 */
	 
	// Initialize Selectize.
	$("#sfwc_option_subaccount_default_role_select_role").selectize({
		placeholder: 'Select new subaccount default role(s)...',
		plugins:
		[
			"remove_button",
		]
	});
	
	// Show/hide sub-options conditionally, based on which radio button is checked.
	$('[name="sfwc_options[sfwc_option_subaccount_default_role]"]').on('change', function(){
		if($(this).is(':checked') && $(this).attr('id') == 'select_role' ) {
			$('#sfwc_option_subaccount_default_role_select_role_wrap').show(500);
			$('#keep_roles_synced_label').hide(500);
		}
		else{
			$('#sfwc_option_subaccount_default_role_select_role_wrap').hide(500);
			$('#keep_roles_synced_label').show(500);
		}
	});
	
	
	
	
	/**
	 * "Frontend User Switcher Pane Appearance" setting.
	 */	
	
	$('#sfwc-user-switcher-pane').css('background-color', ($('#sfwc_switcher_pane_bg_color').val()));
	$('#sfwc_switcher_pane_bg_color').wpColorPicker({
		change: function (event, ui) {
			var theColor = ui.color.toString();
			$('#sfwc-user-switcher-pane').css('background-color', theColor);
		}
	});
	
	
	$('#sfwc-user-switcher-pane h3').css('color', ($('#sfwc_switcher_pane_headline_color').val()));
	$('#sfwc_switcher_pane_headline_color').wpColorPicker({
		change: function (event, ui) {
			var theColor = ui.color.toString();
			$('#sfwc-user-switcher-pane h3').css('color', theColor);
		}
	});
	
	
	$('#sfwc-user-switcher-pane p').css('color', ($('#sfwc_switcher_pane_text_color').val()));
	$('#sfwc_switcher_pane_text_color').wpColorPicker({
		change: function (event, ui) {
			var theColor = ui.color.toString();
			$('#sfwc-user-switcher-pane p').css('color', theColor);
		}
	});
	
	
	$('#sfwc-user-switcher-pane select').css('background-color', ($('#sfwc_switcher_pane_select_bg_color').val()));
	$('#sfwc_switcher_pane_select_bg_color').wpColorPicker({
		change: function (event, ui) {
			var theColor = ui.color.toString();
			$('#sfwc-user-switcher-pane select').css('background-color', theColor);
		}
	});
	
	
	$('#sfwc-user-switcher-pane select').css('color', ($('#sfwc_switcher_pane_select_text_color').val()));
	$('#sfwc_switcher_pane_select_text_color').wpColorPicker({
		change: function (event, ui) {
			var theColor = ui.color.toString();
			$('#sfwc-user-switcher-pane select').css('color', theColor);
		}
	});
	
	
	/* Restore default color scheme */
	jQuery('#sfwc-user-switcher-pane-default-values').on('click', function () {

		$('#sfwc_switcher_pane_bg_color').val('#def6ff'); // Reset input value
		$('#sfwc_switcher_pane_bg_color').closest('.wp-picker-container').children('.wp-color-result').css('background-color', '#def6ff'); // Reset wp color picker box
		$('#sfwc-user-switcher-pane').css('background-color', '#def6ff'); // Reset User Switcher preview

		$('#sfwc_switcher_pane_headline_color').val('#3577c9');
		$('#sfwc_switcher_pane_headline_color').closest('.wp-picker-container').children('.wp-color-result').css('background-color', '#3577c9');
		$('#sfwc-user-switcher-pane h3').css('color', '#3577c9');

		$('#sfwc_switcher_pane_text_color').val('#3b3b3b');
		$('#sfwc_switcher_pane_text_color').closest('.wp-picker-container').children('.wp-color-result').css('background-color', '#3b3b3b');
		$('#sfwc-user-switcher-pane p').css('color', '#3b3b3b');

		$('#sfwc_switcher_pane_select_bg_color').val('#3577c9');
		$('#sfwc_switcher_pane_select_bg_color').closest('.wp-picker-container').children('.wp-color-result').css('background-color', '#3577c9');
		$('#sfwc-user-switcher-pane select').css('background-color', '#3577c9');

		$('#sfwc_switcher_pane_select_text_color').val('#ffffff');
		$('#sfwc_switcher_pane_select_text_color').closest('.wp-picker-container').children('.wp-color-result').css('background-color', '#ffffff');
		$('#sfwc-user-switcher-pane select').css('color', '#ffffff');
	});
				
				
				
	

})( jQuery );