(function($){
  $.fn.prettifyForm = function() {
    return this.each(function() {
      $(this).find('select').change(function() {
        var $label = $('label[for='+this.id+'-button]');
        $label.hide();
      });
      $(this).find(':input').focus(function() {
        var $label = $('label[for='+this.id+']');
        if(this.value.length) {
          $label.hide();
        } else {
          $label.show().css({ opacity: 0.5 });
        }
      })
      .blur(function() {
        var $label = $('label[for='+this.id+']');
        if(this.value.length) {
          $label.hide();
        } else {
          $label.show().css({ opacity: 1 });
        }
      })
      .keypress(function() {
        var $label = $('label[for='+this.id+']');
        if(this.value.length) {
          $label.hide();
        } else {
          $label.show().css({ opacity: 0.5 });
        }
      });
    });
  }
})(jQuery);

$(function() {
  $(':input, :submit').each(function() {
    $(this).addClass($(this).attr('type'));
  });
  $('.col:first-child').addClass('first-col');
  $('select').selectmenu();
  
  $('#demo form, #main form')
    .prettifyForm()
    .validate();
    
  // $('[required]').each(function() {
  //   var $input = $(this);
  //   $(this).closest('.field').append($('<img src="wp-content/themes/alkami/images/asterisk.png" />').position({ my: 'left top', at: 'right top', of: $input }));
  // });
  
  $('form#support').submit(function(e) {
    e.preventDefault();
    $(this).find('.errors').html('Login information is invalid.');
  });
  
  $('#online-banking-masthead section').cycle({ 
    fx:     'fade', 
    speed:  1000, 
    pause: 1,
    pauseOnPagerHover: 1,
    timeout: 5000, 
    pager:  '#online-banking-masthead nav.sub',
    pagerAnchorBuilder: function(idx, slide) { 
      return '#online-banking-masthead nav.sub a:nth-child('+(idx+1)+')'; 
    }
  });
  
  $('#business-slides').cycle({ 
    fx:     'turnUp',
    pause: 1,
    pauseOnPagerHover: 1,
    speed:  1000, 
    timeout: 5000, 
    pager:  'div.business nav',
    pagerAnchorBuilder: function(idx, slide) { 
      return 'div.business nav a:nth-child('+(idx+1)+')'; 
    }
  });
});


