/**
 *  Initialize select JS
 */
var selectDropdownStyles = (function ($) {

  var pub = {}; // public facing functions

  pub.init = function () {
    pub._selectizeDropdown('.address_state select');
    pub._selectizeDropdown('.address_country select');
    pub._selectizeDropdown('.ginput_container_time select');
    pub._selectizeDropdown('.gfield_select');
    pub._selectizeDropdown('.widget select');
  };

  /**;
  * Call Select function to style form dropdowns
  */
  pub._selectizeDropdown = function (element) {
    var selectElement = $(element);
    if (selectElement.length > 0) {
      selectElement.selectize();
    }
  };

  return pub;

})(jQuery);

/* Transform dropdowns into selectize after failed form submit */
jQuery('form').on('submit', function () {
  jQuery(document).bind('gform_post_render', function(){
    selectDropdownStyles.init();
  });
})