(function($) {
  $(function() { 
    /* =============  трясем иконку ============= */
    function drag_icon() {
      $(".nav_game").addClass("tada");
      setTimeout(function() {
          $(".nav_game").removeClass("tada");
      }, 2000);

      setTimeout(drag_icon, 5000);
    }
    setTimeout(drag_icon, 5000);



     /* =============  подписчиков в вк ============= 

      $.ajax({  
        url: 'http://api.vk.com/method/groups.getById?gid=41465061&fields=members_count',  
        dataType: "jsonp",  
        success:function(e){ 
          $('#vk_count').html(e.response[0].members_count) 
        }  
      }); 

      $.ajax({
        url: 'http://api.facebook.com/method/links.getStats?urls=https://www.facebook.com/liftmarketingmedia&format=json',
        dataType: "jsonp",
        success: function(data){
          $('#fb_count').html(data[0].total_count);
        }
      });
      $.ajax({
        url: 'http://urls.api.twitter.com/1/urls/count.json?url=https://twitter.com/kyrylenkovyach',
        dataType: "jsonp",
        success: function(data){
          $('#tw_count').html(data.count);
        }
      });
      var profileid = '111663358623833774156';
      var apikey = 'AIzaSyDKF3y8vzAk6dL0iQc732CkefYlZNOivsY';
      var url = 'https://www.googleapis.com/plus/v1/people/' + profileid + '?key=' + apikey;
      $.ajax({
          type: "GET",
          dataType: "json",
          url: url,
          success: function (data) {
              var googlefollowcount = data.circledByCount;
              $('#gp_count').html(googlefollowcount);
          }
      });
*/
    /* =============  колонки новостей ============= */
     $(".boxes_n_col").each(function(){
      $(this).find(".boxes_n_item:first").show();
      $(this).find(".boxes_n_item_short:first").hide();
    });

    /* ============= hide side ============= */

    var hide_side_trig = 0;
    var hide_side =  $.cookie("hide_side");
    if (hide_side == "1") {
        hide_side_trig = 1;
        $("#colum_right").hide();
        $('.hide_side').addClass("active");
        $(".users_news, .boxes_news").addClass("long");
        $("#colum_left").animate({"width":"1230px"}, function(){
         $(".short_news").each(function(){
             $(this).css({"width":"292px"});
          });
           $('.mas_news').masonry({
              itemSelector: '.short_news',
              singleMode: false,
              isResizable: true,
              "gutter": 20,
              isAnimated: true,
                  animationOptions: { 
                  queue: false, 
                  duration: 500 
              }
           });
           $.cookie("hide_side", "1", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
          });
        });
    }       


    $('.hide_side').click(function(){
      $("#colum_right").fadeToggle();
      $(this).toggleClass("active");
      if (hide_side_trig == 0) {
        hide_side_trig = 1;
        $(".users_news, .boxes_news").addClass("long");
        $("#colum_left").animate({"width":"1230px"}, function(){
         $(".short_news").each(function(){
             $(this).css({"width":"292px"});
          });
           $('.mas_news').masonry({
              itemSelector: '.short_news',
              singleMode: false,
              isResizable: true,
              "gutter": 20,
              isAnimated: true,
                  animationOptions: { 
                  queue: false, 
                  duration: 500 
              }
           });
           $.cookie("hide_side", "1", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
          });
           $('.boxes_slider').bxSlider({
            slideSelector:'.boxes_slider_item',
            pagerCustom:'#bsi_nav_liks',
            controls:false
          }); 
        });
      } else {
        hide_side_trig = 0;
        $(".users_news, .boxes_news").removeClass("long");
        $("#colum_left").animate({"width":"910px"}, function(){
         $(".short_news").each(function(){
             $(this).css({"width":"289px"});
          });

          $('.mas_news').masonry({
            itemSelector: '.short_news',
            singleMode: false,
            isResizable: true,
            "gutter": 20,
            isAnimated: true,
                animationOptions: { 
                queue: false, 
                duration: 500 
             }
          });
          $.cookie("hide_side", "2", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
          });
          $('.boxes_slider').bxSlider({
            slideSelector:'.boxes_slider_item',
            pagerCustom:'#bsi_nav_liks',
            controls:false
          }); 
        });
      }
      
    });
    

    /* ============= чат ============= */

    $('.ch_bt, .chat_box_title_close').click(function(){
      $(".chat_hide").slideToggle();
      $(".chat_box_title_close").toggleClass('oupen');
    });

    var cbts_triger = 0;
    var chat_title_cookie =  $.cookie("chat_title");
    if (chat_title_cookie == "1") {
      cbts_triger = 0;
      $(".chat_box_title").css({'width':'60px'});
      $('.chat_box_title_slide').addClass('to_slide');
    }
    $('.chat_box_title_slide').click(function(){
      $('.chat_box_title_slide').toggleClass('to_slide');
      if (cbts_triger == 0) {
        cbts_triger = 1;
        $(".chat_box_title").animate({'width':'60px'});
         $.cookie("chat_title", "1", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
          });
      } else {
        cbts_triger = 0;
        $(".chat_box_title").animate({'width':'270px'});
         $.cookie("chat_title", "2", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
          });
      }
    });

    $('.chat_box').draggable({
        handle: $('.chat_box_title, .chat_b_icon_move')
    });
    /* =============  игры ============= */

    $('.show_head_games').click(function(){
      $(".shg_box").slideToggle();
    });
    

   /* =============  грузим больше новостей ============= */

    $('.efir').click(function(){
      $(".to_blur").addClass("active");
      $(".efir_window").fadeIn();
      $(".twich_iframe").each(function(){
        var tw_iframeurl = $(this).data("iframeurl");
        $(this).find("iframe").attr('src',tw_iframeurl);
      });
    });
    $(".efir_mask, .twich_close").click(function(){
      $(".to_blur").removeClass("active");
      $(".efir_window").fadeOut();
      $(".twich_iframe").each(function(){
        $(this).find("iframe").attr('src','');
      });
    });

    var play_video_triger = 0;
    $('.hmp_video').on('click', function(){
      if (play_video_triger == 0) {
        play_video_triger = 1;
         $(".hot_news_move video").get(0).pause();
         $(this).addClass("puse");
      } else {
        play_video_triger = 0;
         $(".hot_news_move video").get(0).play();
         $(this).removeClass("puse");
      } 
    });

    var head_pict_bg_slider = $('.head_pict_bg').bxSlider({
      slideSelector:'.head_pict_bg_item',
      auto: true,
      mode: 'fade',
      speed: 900,
      controls:false,
      pause: 9000
    }); 



    var play_slide_triger = 0;
    $('.hmp_slide').on('click', function(){
      if (play_slide_triger == 0) {
        play_slide_triger = 1;
         head_pict_bg_slider.stopAuto();
         $(this).addClass("puse");
      } else {
        play_slide_triger = 0;
        head_pict_bg_slider.startAuto();
        $(this).removeClass("puse");
      } 
    });


     /* ============= слайдер  ============= */

    $('.bxslider').bxSlider({
      slideSelector:'a',
      adaptiveHeight: true,
      controls:false
    }); 
   

   

     /* ============= слайдер в шапке  ============= 
     $('.head_slider').bxSlider({
      slideSelector:'.head_slider_item',
      pager:false
    });       
    */
    

    /* ============= адаптивный тригер  ============= */
    var windowwidth = $(window).width();
    var windowheight = $(window).height();
    if (windowwidth <= "1279") {
      var checkmobile = true
    }

    /* ============= фон ноости  ============= */
   /* if ($(".all_news").index() != "-1") {
        var gan_background = $(".all_news").find("img:first").attr("src");
        $(".all_news").css("background-image","url("+gan_background+")");
    }
    if ($(".overview_news").index() != "-1") {
        var gan_background = $(".overview_news").find("img:first").attr("src");
        $(".overview_news").css("background-image","url("+gan_background+")");
    }
    if ($(".pub_news").index() != "-1") {
        var gan_background = $(".pub_news").find("img:first").attr("src");
        $(".pub_news").css("background-image","url("+gan_background+")");
    }
    */
    if ($(".fsp_pict").index() != "-1") {
        var gan_background = $("#colum_left").find("img:first").attr("src");
        $(".fsp_pict").css("background-image","url("+gan_background+")");
    }

     /* ============= фон баннер ан формуе   ============= */
     if ($(".forum_banner").index() != "-1") {
      $(".forum_banner").each(function(){
        var banner_url = $(this).find("img:first").attr("src");
        $(this).parents(".cl_item").find(".left_icon_forum").css("background-image","url("+ banner_url +")");
      });
     }
     if ($(".right_info_forum").index() != "-1") {
      $(".right_info_forum").each(function(){
        var right_info_forum_img_url = $(this).find(".avatar_info_forum").find("img:first").attr("src");
        $(this).find(".right_info_forum_pict").css("background-image","url("+ right_info_forum_img_url +")");
      });
     }

    /* ============= масонри  ============= */

    $(".addnews_form li input[type=checkbox]").styler();
    $(".vote input, .pm_list input[type=checkbox], .pm_head input[type=checkbox]").styler();
    $(".sui_sort input, .sui_sort select").styler();
 

    $('.tn_author').each(function(){
      var tn_comment_id = $(this).attr("ID");
      $(".cn_item_com_anshors").find("ul").append('<li class="scroll" data-target="'+tn_comment_id+'"></li>');
      console.log($('.tn_author').index());
      if ($('.tn_author').index() != "") {
        $('.cn_show_my').show();
      };
    });

    var mycomtriger = 0;
    $('.cn_show_my').click(function(){
      $(".cn_item_com_anshors").fadeToggle();
      if(mycomtriger==0){
        mycomtriger = 1;
         $(this).text("Отметить подсветку моих комментарие");
         $('.tn_author').each(function(){
            $(this).addClass("tn_author_color");
            $(this).addClass("tn_author_color");
          });
      } else {
        mycomtriger = 0;
         $(this).text("Подсветить мои комментарии");
         $('.tn_author').each(function(){
            $(this).removeClass("tn_author_color");
            $(this).removeClass("tn_author_color");
          });
      }
      
    });
      /* ============= nav menu  ============= */
   var TriggerClick = 0;
   
    $(".nav_icon").click(function () { 
      var menutop = $(".menu_panel").css("top");
      if(TriggerClick==0){
           TriggerClick=1;
           $(this).addClass("active");
           $(".menu_panel").slideDown();
        }else{
          TriggerClick=0;
          $(this).removeClass("active");
          $(".menu_panel").slideUp();
        }      
    }); 
     /* ============= саудио ============= */
    var TriggerClickAudio = 0;
   
    $(".audio_player_title").click(function () { 
      var menutop = $(".menu_panel").css("top");
      if(TriggerClickAudio==0){
           TriggerClickAudio=1;
            $(".audio_player").animate({"width":"300px"});
            $(".menu_icons").fadeOut();
        }else{
          TriggerClickAudio==0;
           $(".audio_player").animate({"width":"0px"});
           $(".menu_icons").fadeIn();
      }      
    }); 

    var head_bg_trig = 0;
    var head_bg =  $.cookie("head_bg");
    if (head_bg == "1") {
      head_bg_trig = 1;
      $(".hot_news_move").show();
      $(".head_pict_bg_box").hide();
      $(".head_move_swith").removeClass("pict");
      $('.hmp_slide').hide();
      $('.hmp_video').show();
    }
     $(".head_move_swith").click(function () { 
      if (head_bg_trig == 0) {
        head_bg_trig = 1;
        $(".hot_news_move").show();
      $(".head_pict_bg_box").hide();
        $(".head_move_swith").removeClass("pict");
       $('.hmp_slide').hide();
      $('.hmp_video').show();
         $.cookie("head_bg", "1", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
          });
      } else {
        head_bg_trig = 0;
        $(".hot_news_move").hide();
        $(".head_pict_bg_box").show();
        $(".head_move_swith").addClass("pict");
        $('.hmp_slide').show();
        $('.hmp_video').hide();

        $.cookie("head_bg", "2", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
          });
      }
    });

     /* ============= jurnal  ============= */


         
    /* ============= show_fix_menu  =============


    if ($(".grid_all_news").index() != "-1") {
         var show_fix_menutrig = 0;
        var check_grid =  $.cookie("main_grid");
        if (check_grid == "1") {
          $(".short_news, .jurnal_item").hide();
            $(".short_news_def").show();
             $(".sfm_active").removeClass("sfm_active");
          $(".sfm_1").addClass("sfm_active");
          $(".short_news").css({"width":"1010px"});
          $(".structure_main_box").attr('id','structure_def');
        }
        if (check_grid == "2") {
           $(".short_news_def, .jurnal_item").hide();
             $(".short_news").show();
             $("sfm_active").removeClass("sfm_active");
          $(".sfm_2").addClass("sfm_active");
          $(window).load(function(){ 
           $('.grid_all_news').masonry({
                      itemSelector: '.short_news',
                      singleMode: false,
                      isResizable: true,
                      "gutter": 20,
                      isAnimated: true,
                          animationOptions: { 
                          queue: false, 
                          duration: 500 
                      }
                });
          });
        }
        if (check_grid == "3") {
           $(".short_news_def, .short_news").hide();
            $(".sfm_active").removeClass("sfm_active");
            $(".jurnal_item").show();
          $(".sfm_3").addClass("sfm_active");

          $(".structure_main_box").attr('id','structure_masonry_jurnal');
           $(".grid_all_news").find(".jurnal_item").each(function(){ 
              console.log($(this).index());
            if ($(this).index() == 8 || $(this).index() == 23) {
              $(this).addClass("big");
            }
           });
         $(window).load(function(){ 
           $('.grid_all_news').masonry({
                    itemSelector: '.jurnal_item',
                    singleMode: false,
                    isResizable: true,
                    "gutter": 10,
                    isAnimated: true,
                        animationOptions: { 
                        queue: false, 
                        duration: 500 
                    }
              });
        });
        }
    };
    

    $(".show_fix_menu").click(function () { 
      if ($(this).hasClass("sfm_1")) {
        $(".short_news, .jurnal_item").hide();
        $(".short_news_def").show();
         console.log("клик на деф");
        $(".sfm_active").removeClass("sfm_active");
        $(this).addClass("sfm_active");
         $(".short_news").css({"width":"1010px"});
         $('.grid_all_news').masonry('destroy');
         $(".structure_main_box").attr('id','structure_def');

          $.cookie("main_grid", "1", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
          });
      }
      if ($(this).hasClass("sfm_2")) {
        $(".short_news_def, .jurnal_item").hide();
         $(".short_news").show();
        $(".sfm_active").removeClass("sfm_active");
        $(this).addClass("sfm_active");
          $(".short_news").css({"width":"290px"});
          $('.grid_all_news').masonry('destroy');
          $(".structure_main_box").attr('id','structure_masonry');
           $('.grid_all_news').masonry({
              itemSelector: '.short_news',
              singleMode: false,
              isResizable: true,
              "gutter": 20,
              isAnimated: true,
                  animationOptions: { 
                  queue: false, 
                  duration: 500 
              }
        });
        $(".side_box_masonry").removeClass("side_box_default").addClass("side_box_masonry");
        $(".side_box_masonry").removeClass("structure_masonry_jurnal").addClass("side_box_masonry");

         $.cookie("main_grid", "2", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
        });
      }
      if ($(this).hasClass("sfm_3")) {
        $(".short_news_def, .short_news").hide();
        $(".jurnal_item").show();
        $(".sfm_active").removeClass("sfm_active");
        $(this).addClass("sfm_active");
          $(".short_news").css({"width":"290px"});
          $('.grid_all_news').masonry('destroy');
         $(".structure_main_box").attr('id','structure_masonry_jurnal');
          $(".grid_all_news").find(".jurnal_item").each(function(){ 
              console.log($(this).index());
            if ($(this).index() == 8 || $(this).index() == 23) {
              $(this).addClass("big");
            }
           });
           $('.grid_all_news').masonry({
              itemSelector: '.jurnal_item',
              singleMode: false,
              isResizable: true,
              "gutter": 10,
              isAnimated: true,
                  animationOptions: { 
                  queue: false, 
                  duration: 500 
              }
        });
        $(".side_box_masonry").removeClass("side_box_default").addClass("side_box_masonry");
         $.cookie("main_grid", "3", {
             expires : 360,           //expires in 10 days
             path    : '/',          //The value of the path attribute of the cookie 
             domian  : 'mexalim.com.ua'
        });
      }
    }); 
 */
    /* ============= Поделиться  ============= */
    $('.fsp_share_scial li a').click(function(event) {
        event.preventDefault();
        window.open($(this).attr("href"), "popupWindow", "width=600,height=600,scrollbars=yes");
    });
  /* ============= рейтинг юзера  ============= */
  if ($(".uhc_rating").index() != "-1") {

    var user_news_rate = $(".uhc_news_rate > span").text();
    var user_com_rate = $(".uhc_news_rate > span").text();
    var user_news_rate_p = parseInt(user_news_rate);
    var user_com_rate_p = parseInt(user_com_rate);

    var user_rate = user_news_rate_p;
    $(".uhc_rating").text(user_rate);

    if (user_rate == 1) {
      $(".up_ratingline").addClass("good");
    }
    if (user_rate >= 2) {
      $(".up_ratingline").addClass("super_good");
    }
  }

  /* =============  цвет шапки фуллстори  ============= */
  if ($(".cn_item").index() != "-1") {
   $('.cn_item').each(function(){
      var tn_comment_rate = $(this).find(".ratingtypeplus").text();
      var tn_comment_rate_p = parseInt(tn_comment_rate);
      if (tn_comment_rate_p >= 1) {
        $(this).addClass("good");
      };
    });
  }

  /* =============  цвет шапки фуллстори  ============= */
  if ($(".fsp_sl_num").index() != "-1") {
    var full_rate_num = $(".fsp_sl_num").text();
    if (full_rate_num == 1) {
      $(".fsp_title_box").addClass("good");
    }
    if (full_rate_num >= 2) {
      $(".fsp_title_box").addClass("super_good");
    }
  }

  /* =============  цвет плашок на главной  ============= */
  if ($(".mas_news").index() != "-1") {
      $('.short_news').each(function(){
        var home_pub_rate = $(this).find("span.ratingtypeplus").text();
        var home_pub_rate_p = parseInt(home_pub_rate);

       if (home_pub_rate_p == 1) {
          $(this).find('.hni_overview_info_line').addClass("good");
        }
        if (home_pub_rate_p >= 2) {
          $(this).find('.hni_overview_info_line').addClass("super_good");
        }
      });
  }

  /* ============= грузим новости юзера ============= */
  if ($("#user_news").index() != "-1") {
    var user_link = $(".user_link").find("a").attr("href");
  }
 $.ajax({
     url:user_link,
     type:'GET',
     success: function(data){
         $('#user_news').html($(data).find('#dle-content').html());
 

       }
    });


    /* =============  авка ============= */
    $('.ui_upload_av').click(function(){
      $(".ui_upload_av_input").click();
    });
    $(".ui_upload_av_input").change(function(){
      $(".ui_upload_av").addClass("active");
    });
    /* =============  авка ============= */
    $('.vk_bt').hover(function(){
      $(".vk_widjet").fadeToggle(100);
    });


  /* =============  scroll  ============= */
    $('.scroll').click(function(){
       var sel = $(this).data("target");
      var destination = $("#"+ sel).offset().top - 1;
      $("body,html").animate({ scrollTop: destination}, 500 );
    });

  /* =============  фиксм панель управления комментами  ============= */

  if ($(".fsp_sl_num").index() != "-1") {

  var banner_to_fix = $("#comments_news").offset();
  var banner_to_fix_top = banner_to_fix.top;
    $(window).scroll(function () {
      if ($(this).scrollTop() >= banner_to_fix_top -100) {
        $('.cn_item_com_anshors').addClass("fix");
      } else {
        $('.cn_item_com_anshors').removeClass("fix");
      }
  });
  }

  /* =============  держим енота  ============= */
  
  if ($(".racoon_page").index() != "-1") {


    var racoon_end = $("#racoon_not_fix").offset().top
    var h = $(".grid_all_news").css('height');
    var h_p = parseInt(h);
   $(document).scroll(function(){
        console.log(racoon_end + h_p);
        console.log($(this).scrollTop());
        if ($(this).scrollTop() >= racoon_end + h_p){
          $('.racoon_page_pict').addClass("not_fix");
         } else {
           $('.racoon_page_pict').removeClass("not_fix");
         }
    });

  }
/* =============  приветствие ============= */
 var welcomemaintext_cook = $.cookie("welcome_main_text");
 var welcome_botton_triger = 0;

  if (welcomemaintext_cook == "1") {
  
    welcome_botton_triger = 1;
    $(".welcome_main_text_in").hide();
  }
  $(".welcome_botton").click(function(){
    // $(".welcome_main_text").hide();
    if (welcome_botton_triger == 0) {
       welcome_botton_triger = 1;
        $.cookie("welcome_main_text", 1, {
         expires : 365,           //expires in 10 days
         path    : '/',          //The value of the path attribute of the cookie 
         domian  : 'mexalim.com.ua'
      });
        $(".welcome_main_text_in").hide();
    } else {
       welcome_botton_triger = 0;
        $.cookie("welcome_main_text", 2, {
         expires : 365,           //expires in 10 days
         path    : '/',          //The value of the path attribute of the cookie 
         domian  : 'mexalim.com.ua'
      });
        $(".welcome_main_text_in").show();
    }
    
  });
console.log(welcome_botton_triger);


  /* =============  аватар в профиль ============= */

  var user_img_link = $(".lb_av").find("img").attr("src");
  $(".tp_av, .acf_av").find("img").attr("src",user_img_link);

  /* =============  фикс шапки ============= */
  var head_fix_cook = $.cookie("head_fix");
  var head_fix_triger = 0;
  if (head_fix_cook == "1") {
   head_fix_triger = 1;
   $('.top_panel, .top_panel_mask,.search_panel').addClass("tp_fix");
  }

  $('.tp_lock').click(function(){
    console.log("закрепить");
    $(".search_panel").slideUp();
    if (head_fix_triger == 0) {
       head_fix_triger = 1;
       console.log("да");
       $('.top_panel, .top_panel_mask,.search_panel').addClass("tp_fix");
       $.cookie("head_fix", 1, {
         expires : 365,           //expires in 10 days
         path    : '/',          //The value of the path attribute of the cookie 
         domian  : 'mexalim.com.ua'
      });
    } else {
      console.log("нет");
      head_fix_triger = 0;
      $('.top_panel, .top_panel_mask,.search_panel').removeClass("tp_fix");
      $('.top_panel, .top_panel_mask').animate({"top":"0px"});
      $.cookie("head_fix", 2, {
         expires : 365,           //expires in 10 days
         path    : '/',          //The value of the path attribute of the cookie 
         domian  : 'mexalim.com.ua'
      });
    }
    
  });

   /* ============= sb_bt ============= */
   var sb_bt_trig = 0;
   $('.sb_bt').click(function(){
      $(".search_panel").slideToggle();
        if (head_fix_triger == "1") {
          if (sb_bt_trig == 0) {
            sb_bt_trig = 1;
            $('.top_panel, .top_panel_mask').animate({"top":"81px"});
          } else {
            sb_bt_trig = 2;
            $('.top_panel, .top_panel_mask').animate({"top":"0px"});
          }
         
        }
      $(this).toggleClass("active");
   });

  /* =============  контакты ============= */

  $('.kontakt_window_bottom').click(function(){
    $(".to_blur").addClass("active");
    $(".kontakt_window").fadeIn();
    $(".kontakt_window_mask").fadeIn();
  });
  $(".kontakt_window_mask").click(function(){
    $(".to_blur").removeClass("active");
    $(".kontakt_window_mask").fadeOut();
    $(".kontakt_window").fadeOut();
  });

  /* =============  games_list ============= */

  $('.games_list_show').click(function(){
    $(".to_blur").addClass("active");
    $(".games_list_mask").fadeIn();
    $(".games_list").fadeIn();
  });
  $(".games_list_mask, .games_list_close").click(function(){
    $(".to_blur").removeClass("active");
    $(".games_list_mask").fadeOut();
    $(".games_list").fadeOut();
  });

  $(".gl_filtres li").click(function(){
    var filter_class = $(this).data("filter")
    $(this).toggleClass("active");
    $(".gl_item").each(function(){
      if (!$(this).hasClass(filter_class)) {
        $(this).fadeToggle();
      }
    });
  })

   /* =============  кнопки ============= */

  $('.tp_login_box, .acf_block_button, .tp_button, .to_show_login').click(function(){
    $(".to_blur").addClass("active");
    $(".login_mask").fadeIn();
    $(".login_panel").fadeIn();
    TriggerClick=0;
          $(".nav_icon").removeClass("active");
          $(".menu_panel").slideUp();
  });
  $(".login_mask, .lp_close").click(function(){
    $(".to_blur").removeClass("active");
    $(".login_mask").fadeOut();
    $(".login_panel").fadeOut();
  });


  $('.hni_move').click(function(){
    var hni_move_id = $(this).attr("id");
    $("#news_move_window_"+hni_move_id).addClass("nmw_oupen");
    $("#news_move_window_"+hni_move_id).fadeIn();
    $(".hni_move_mask").show();
  });

  $('.hni_move_mask').click(function(){
    var hni_move_id = $(this).attr("id");
    var hni_move_url = $(".nmw_oupen").find("iframe").attr('src');
    $(".nmw_oupen").hide();
    $(".nmw_oupen").find("iframe").attr('src');
    $(".nmw_oupen").find("iframe").attr('src',hni_move_url);
    
    $("#news_move_window_"+hni_move_id).removeClass("nmw_oupen");
    $(".hni_move_mask").fadeOut();
  });

     $('.chat_scroll').scrollbar();
     $('.comments_scroll').scrollbar();
     $('.gl_items_box').scrollbar();
     $('#iChat-style').scrollbar();


  $(".tp_com_link").click(function(){
    $(".comments_panel").animate({"left":"0px"});
    $(".com_panel_mask").fadeIn();
  });
 
 
  $(".com_panel_mask").click(function(){
    $(".to_blur").removeClass("active");
    $(".com_panel_mask").hide();
    $(".comments_panel").animate({"left":"-508px"});
  });

   $(".chat_link").click(function(){
    $(".chat_panel").animate({"right":"0px"});
    //$(".to_blur").addClass("active");
    $(".chat_panel_mask").fadeIn();
    /*$.ajax({
     url:"http://mexalim.com.ua/dle105/index.php?do=lastcomments",
     type:'GET',
     success: function(data){
         $('#comments_container').html($(data).find('#dle-comments-list').html());
         $('.comments_panel').removeClass("load");

       }
    });
*/
  });
  $(".chat_panel_mask").click(function(){
    $(".to_blur").removeClass("active");
    $(".chat_panel_mask").hide();
    $(".chat_panel").animate({"right":"-500px"});
  });

  /* =============  галерея ============= */
  /*scrull top bottom*/
  $('.top_link').click(function(){
       $('html,body').animate({scrollTop: $("#head").offset().top},'slow');
  });

  /*megic gallery by mexalim*/

$("#fan_gallery").each(function(){
  var box = $(this).find(".fan_g_thamp:first");
  $(this).append("<a href='#' class='fan_g_perv'></a><a href='#' class='fan_g_next'></a>");
  $(this).find("a").attr('onclick','').unbind('click');
  $(this).find("a").attr('rel','').unbind('click');
  box.find("br").remove();
  box.find("a:first").addClass("show");
  var firstpict = box.find("a:first").attr('href');
  $(this).find(".fan_g_show").append("<img src=" + firstpict + " alt='' />");
    
  $('.fan_g_thamp').find("a").click(function(event){
    event.preventDefault();
    var link = $(this).attr('href');
    
    $(".fan_g_show").html("<img src=" + link + " alt='' />");
    $(".show").removeClass("show");
    $(this).addClass("show");
  });

  $(".fan_g_next").click(function(event){
     event.preventDefault();
    $("#fan_gallery").find(".show").removeClass("show").nextAll('a:first').addClass("show");
    if ($("#fan_gallery").find(".show").prevAll('a:first').length) { 
     
    } else {
      if ($('.fgo_active').nextAll('.fan_g_thamp').length) { 

        $(".fgo_active").removeClass("fgo_active").next(".fan_g_thamp").addClass("fgo_active");
        $(".fgo_active").find('a:first').addClass("show");
      } else {
        $(".fgo_active").removeClass("fgo_active");
       $("#fan_gallery").find(".fan_g_thamp:first").addClass("fgo_active");
        $(".fgo_active").find('a:first').addClass("show");
      }
    }
    var link = $(".show").attr('href');
    $(".fan_g_show").html("<img src=" + link + " alt='' />");
  });

  $(".fan_g_perv").click(function(event){
     event.preventDefault();
    $("#fan_gallery").find(".show").removeClass("show").prevAll('a:first').addClass("show");
    if ($("#fan_gallery").find(".show").prevAll('a:first').length) { 
       console.log("lastprev");
    } else {
      if ($('.fgo_active').prevAll('.fan_g_thamp').length) { 
        $(".fgo_active").removeClass("fgo_active").next(".fan_g_thamp").addClass("fgo_active");
        $(".fgo_active").find('a:first').addClass("show");
      } else {
        $(".fgo_active").removeClass("fgo_active")
        $("#fan_gallery").find(".fan_g_thamp:last").addClass("fgo_active");
        $(".fgo_active").find('a:last').addClass("show");
      }
    }
    var link = $(".show").attr('href');
    $(".fan_g_show").html("<img src=" + link + " alt='' />");
  });  
    
});
 $(window).load(function(){ 
  $('.vk_widjet').hide();
     $('.vk_widjet').css({"z-index":"4"});
  $(".preloader").fadeOut();
   $('.boxes_slider').bxSlider({
      slideSelector:'.boxes_slider_item',
      pagerCustom:'#bsi_nav_liks',
      controls:false
    }); 
 });
});
$(function() {  
  $('ul.tabs').on('click', 'li:not(.current)', function() {  
    $(this).addClass('current').siblings().removeClass('current').parents('div.section').find('div.box').eq($(this).index()).fadeIn(150).siblings('div.box').hide();  
  });  
  $('ul.side_tabs').on('click', 'li:not(.current)', function() {  
    $(this).addClass('current').siblings().removeClass('current').parents('div.side_section').find('div.box').eq($(this).index()).fadeIn(150).siblings('div.box').hide();  
  });  

  var sfmts_button_trig = 0;

  $(".sfmts_button").click(function(){
    $(".show_fix_menu_tabs").fadeToggle();
    $(this).parents(".show_fix_menu_tabs_settings").toggleClass('active');
    if (sfmts_button_trig == 0) {
      sfmts_button_trig = 1;
      $(".sfmts_button_info").animate({'left':'140px'});
    } else {
      sfmts_button_trig = 0;
      $(".sfmts_button_info").animate({'left':'34px'});
    }
    
  });

  $('ul.tabs_caption').each(function(i) {
    var storage = localStorage.getItem('tab' + i);
    if (storage) {
      $(this).find('li').removeClass('active').eq(storage).addClass('active')
        .closest('div.section').find('div.tabs__content').removeClass('active').eq(storage).addClass('active');
    }
  });
  $(window).load(function(){ 
   $('.mas_news').masonry({
              itemSelector: '.short_news',
              singleMode: false,
              isResizable: true,
              "gutter": 20,
              isAnimated: true,
                  animationOptions: { 
                  queue: false, 
                  duration: 500 
              }
        });
  });

  $('ul.tabs_caption').on('click', 'li:not(.active)', function() {
     
    $(this)
      .addClass('active').siblings().removeClass('active')
      .closest('div.section').find('div.tabs__content').removeClass('active').eq($(this).index()).addClass('active');
    var ulIndex = $('ul.tabs_caption').index($(this).parents('ul.tabs_caption'));
    console.log(ulIndex);
    localStorage.removeItem('tab' + ulIndex);
    localStorage.setItem('tab' + ulIndex, $(this).index());
    $('.mas_news').masonry({
          itemSelector: '.short_news',
          singleMode: false,
          isResizable: true,
          "gutter": 20,
          isAnimated: true,
              animationOptions: { 
              queue: false, 
              duration: 500 
          }
    });
  });

});
})(jQuery)