(function($) {

  /* globals jQuery */

  "use strict";

  function mfnFieldRadioImg() {

    if( $('.mfn-ui .shop-layout-visual-choose .form-group.visual-options .form-control li input[value="custom_tmpl"]').length ){
      $('.mfn-ui .shop-layout-visual-choose .form-group.visual-options .form-control li input[value="custom_tmpl"]').closest('li').find('a').attr('href', 'edit.php?post_type=template&tab=shop-archive').attr('target', '_blank');
    }

    if( $('.mfn-ui .product-layout-visual-choose .form-group.visual-options .form-control li input[value="custom_tmpl"]').length ){
      $('.mfn-ui .product-layout-visual-choose .form-group.visual-options .form-control li input[value="custom_tmpl"]').closest('li').find('a').attr('href', 'edit.php?post_type=template&tab=single-product').attr('target', '_blank');
    }

    var $group = $('.mfn-ui .form-group.visual-options');

    $group.on('click', '.form-control li a', function(e) {
      var $li = $(this).closest('li');

      if($li.find('input').val() != 'custom_tmpl'){
        e.preventDefault();

        $li.addClass('active').find('input').prop('checked', 'checked').trigger('change');
        $li.siblings('li').removeClass('active').find('input').prop('checked', false);

      }

    });

  }

  /**
   * $(document).ready
   * Specify a function to execute when the DOM is fully loaded.
   */

  $(function($) {
    mfnFieldRadioImg();
  });

})(jQuery);
