 // Only show fontawesome feilds if icon type is fontawesome

 jQuery.each(stla_gf_local_ids.fontawesome, function(key, value) {
		wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
			wp.customize.control( 'gf_stla_form_id_field_icons_'+stla_gf_local_ids.id+'[fontawesome]['+value+']['+key+']', function( control ) {
				var visibility = function() {
					if ( 'fontawesome' === setting.get() ) {
						control.container.slideDown( 180 );
					} else {
						control.container.slideUp( 180 );
					}


				};

				visibility();
				setting.bind( visibility );
			});
		});

	//console.log( 'gf_stla_form_id_field_icons_'+stla_gf_local_ids.id+'[fontawesome]['+key+']['+value+']' );
});

//only show icon position option when image is selected
wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
	wp.customize.control( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-position]', function( control ) {
		var visibility = function() {
			if ( 'image' === setting.get() ) {
				control.container.slideDown( 180 );
			} else {
				control.container.slideUp( 180 );
			}
		};

		visibility();
		setting.bind( visibility );
	});
});

//only show font color option when fontawesome is selected
wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
	wp.customize.control( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-color]', function( control ) {
		var visibility = function() {
			if ( 'fontawesome' === setting.get() ) {
				control.container.slideDown( 180 );
			} else {
				control.container.slideUp( 180 );
			}
		};

		visibility();
		setting.bind( visibility );
	});
});


//only show move icon towards right when fontawesome
wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
	wp.customize.control( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-left]', function( control ) {
		var visibility = function() {
			if ( 'fontawesome' === setting.get() ) {
				control.container.slideDown( 180 );
			} else {
				control.container.slideUp( 180 );
			}


		};

		visibility();
		setting.bind( visibility );
	});
});

//only show move icon towards bottom when fontawesome
wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
	wp.customize.control( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-top]', function( control ) {
		var visibility = function() {
			if ( 'fontawesome' === setting.get() ) {
				control.container.slideDown( 180 );
			} else {
				control.container.slideUp( 180 );
			}


		};

		visibility();
		setting.bind( visibility );
	});
});

//only show move icon towards bottom when fontawesome
wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
	wp.customize.control( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-size]', function( control ) {
		var visibility = function() {
			if ( 'fontawesome' === setting.get() ) {
				control.container.slideDown( 180 );
			} else {
				control.container.slideUp( 180 );
			}


		};

		visibility();
		setting.bind( visibility );
	});
});
// show submit button icons when type is font-awesome

// previous button
wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
	wp.customize.control( 'gf_stla_form_id_field_icons_'+stla_gf_local_ids.id+'[fontawesome][previous-button]', function( control ) {
		var visibility = function() {
			if ( 'fontawesome' === setting.get() ) {
				control.container.slideDown( 180 );
			} else {
				control.container.slideUp( 180 );
			}


		};

		visibility();
		setting.bind( visibility );
	});
});

// Next button
wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
	wp.customize.control( 'gf_stla_form_id_field_icons_'+stla_gf_local_ids.id+'[fontawesome][next-button]', function( control ) {
		var visibility = function() {
			if ( 'fontawesome' === setting.get() ) {
				control.container.slideDown( 180 );
			} else {
				control.container.slideUp( 180 );
			}


		};

		visibility();
		setting.bind( visibility );
	});
});

// Submit button
wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
	wp.customize.control( 'gf_stla_form_id_field_icons_'+stla_gf_local_ids.id+'[fontawesome][submit-button]', function( control ) {
		var visibility = function() {
			if ( 'fontawesome' === setting.get() ) {
				control.container.slideDown( 180 );
			} else {
				control.container.slideUp( 180 );
			}


		};

		visibility();
		setting.bind( visibility );
	});
});




// Only show icon feilds if icon type is image
jQuery.each(stla_gf_local_ids.image, function(fieldId, value) {
	
	// if( jQuery.isArray(value)){
		jQuery.each(value, function(index, fieldType){
			wp.customize( 'gf_stla_form_id_field_icons_options_'+stla_gf_local_ids.id+'[icon-type]', function( setting ) {
				wp.customize.control( 'gf_stla_form_id_field_icons_'+stla_gf_local_ids.id+'['+fieldType+']['+fieldId+']', function( control ) {
					var visibility = function() {
						if ( 'image' === setting.get() ) {
							control.container.slideDown( 180 );
						} else {
							control.container.slideUp( 180 );
						}
					};
	 
					visibility();
					setting.bind( visibility );
				});
			});
			
		});	
});


( function ( $ ) {
	$( function () {
		// Range Slider
		$( 'input.stla-range-btn' ).on( 'mousedown', function () {
			var $range = $( this ),
				$range_input = $range.parent().children( '.stla-range-input' );

			value = $( this ).attr( 'value' );
			$range_input.val( value );

			$( this ).mousemove( function () {
				value = $( this ).attr( 'value' );
				$range_input.val( value );
			} );
		} );

		




		// Range Slider
		$( 'input.stla-range-input' ).on( 'change', function () {
			var $range_input = $( this ),
				$range = $range_input.parent().children( '.stla-range-btn' );

			value = $( this ).attr( 'value' );
			$range.val( value );


	});
	var et_range_input_number_timeout;

		function et_autocorrect_range_input_number( input_number, timeout ) {
			var $range_input = input_number,
				$range       = $range_input.parent().find('.input.stla-range-btn'),
				value        = parseFloat( $range_input.val() ),
			//	reset        = parseFloat( $range.attr('data-reset_value') ),
				step         = parseFloat( $range_input.attr('step') ),
				min          = parseFloat( $range_input.attr('min') ),
				max          = parseFloat( $range_input.attr('max') );

			clearTimeout( et_range_input_number_timeout );

			et_range_input_number_timeout = setTimeout( function() {
				if ( isNaN( value ) ) {
					$range_input.val( reset );
					$range.val( reset ).trigger( 'change' );
					return;
				}

				if ( step >= 1 && value % 1 !== 0 ) {
					value = Math.round( value );
					$range_input.val( value );
					$range.val( value );
				}

				if ( value > max ) {
					$range_input.val( max );
					$range.val( max ).trigger( 'change' );
				}

				if ( value < min ) {
					$range_input.val( min );
					$range.val( min ).trigger( 'change' );
				}
			}, timeout );

			$range.val( value ).trigger( 'change' );
		}

		$('input.et-pb-range-input').on( 'change keyup', function() {
			et_autocorrect_range_input_number( $(this), 1000 );
		}).on( 'focusout', function() {
			et_autocorrect_range_input_number( $(this), 0 );
		});
	} );
	} )( jQuery );

