jQuery(document).ready(function($) {

   $('.wizzard-watch-vid >a').VideoPopup();
    
   // Color Picker 
   $('.pickcolor').click( function(e) {
       colorPicker = jQuery(this).next('div');
       input = jQuery(this).prev('input');
       $(colorPicker).farbtastic(input);
       colorPicker.show();
       e.preventDefault();
       $(document).mousedown( function() {
           $(colorPicker).hide();
       });
   });
   
   $('.color-input').keyup(function() {
   			var _hex = $(this).val(), hex = _hex;
   			if ( hex.charAt(0) != '#' )
   				hex = '#' + hex;
   			hex = hex.replace(/[^#a-fA-F0-9]+/, '');
   			if ( hex != _hex )
   				$(this).val(hex);
   			if ( hex.length == 4 || hex.length == 7 )
   				$(this).css('background-color', hex );
   			else
      			$(this).css('background-color', '');
   		});


   $('input[name="imwb_zonpress_theme_options[postcontent]"]').change(function(){
      if($(this).val() == 'C')
         $('input[name="imwb_zonpress_theme_options[postchars]"]').attr('readonly', false);
      else 
          $('input[name="imwb_zonpress_theme_options[postchars]"]').attr('readonly', true);			
   });  
   
   $('select[name="imwb_zonpress_theme_options[commenttype]"]').change(function(){
      if($(this).val() == '0') {
         $('.comment-type-wp').show();
         $('.comment-type-fb').hide();
      }
      else if($(this).val() == '1') {
         $('.comment-type-wp').hide();
         $('.comment-type-fb').show();
      } 
      else if($(this).val() == '2') {
         $('.comment-type-wp').show();
         $('.comment-type-fb').show();
      } 
      else {
         $('.comment-type-wp').hide();
         $('.comment-type-fb').hide();
      }
   });
   
   $('input[name="imwb_zonpress_theme_options[newmemberaroption]"]').change(function(){
      var val = $(this).val();
      if(val == 'A') {
         $('.aweber-field').show();
         $('.getresponse-field').hide();
         $('.arformoth-field').hide();
         $('.arform-field').hide();
         $('.arformurl-field').hide();
      }
      else if(val == 'G') {
         $('.aweber-field').hide();
         $('.getresponse-field').show();
         $('.arformoth-field').hide();
         $('.arform-field').hide();
         $('.arformurl-field').hide();
      }
      else if(val == 'N') {
         $('.aweber-field').hide();
         $('.getresponse-field').hide();
         $('.arformoth-field').hide();
         $('.arform-field').hide();
         $('.arformurl-field').hide();
      }
      else if(val == 'I') {
         $('.aweber-field').hide();
         $('.getresponse-field').hide();
         $('.arformoth-field').hide();
         $('.arform-field').show();
         $('.arformurl-field').hide();
      }
      else if(val == 'M') {
         $('.aweber-field').hide();
         $('.getresponse-field').hide();
         $('.arformoth-field').hide();
         $('.arform-field').show();
         $('.arformurl-field').show();
      }
      else if(val == 'O') {
         $('.aweber-field').hide();
         $('.getresponse-field').hide();
         $('.arformurl-field').hide();
         $('.arform-field').show();
         $('.arformoth-field').show();
      }
      
   }); 
   
   $('#imwb_plugin_options_editor .scheme').on('click', function() {
      if(confirm("Are you sure you wish to save options and change the color scheme to "+$(this).val())) {
      $('input[name="color-scheme"]').val($(this).attr('id'));
         $('input[type="submit"]').click()
      }   
   });
   
   $('#aweber-deauth').on('click', function() {
      if(confirm("Are you sure you wish to remove the connection to AWeber")) {
      $('input[name="aweber-auth"]').val('deauth');
         $('input[type="submit"]').click()
      }   
   });
       
});

function imwb_ms_unselectAll(selObj)
{
   for (i = 0; i < selObj.options.length; i ++)
   {
      selObj.options[i].selected = false;
   }
}
