
; /* Start:"a:4:{s:4:"full";s:107:"/local/templates/diam/components/bitrix/news/video_new/bitrix/news.detail/.default/script.js?17271593953081";s:6:"source";s:92:"/local/templates/diam/components/bitrix/news/video_new/bitrix/news.detail/.default/script.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/
$(document).ready(function() {
    const $resetButton = $('.quick_search_page_reset');
    const $quickSearchInput = $('input[name="quick_search_page"]');
    const $quickSearchForm = $('.quick_search_page');
    const $searchArea = $('.search_arena');
    function quickSearch() {
        $searchArea.unmark();
        let searchText = $quickSearchInput.val().trim();
        if (searchText.length > 0) {
            let mark = false;
            $searchArea.mark(searchText, {
                "separateWordSearch":false,
                "acrossElements":true,
                "each": function(node){
                    if (!mark && node.offsetHeight>0) {
                        mark = node;
                    }
                },
            });
            if (mark) {
                $('.quick_search_empty').remove();
                $('html, body').animate({
                    scrollTop: $(mark).offset().top-150
                }, 1000);
            } else {
                if (!$quickSearchForm.find('.quick_search_empty').length) {
                    $quickSearchForm.append('<div class="quick_search_empty">Ничего не найдено</div>');
                }
            }
        } else {
            $searchArea.unmark();
        }
    }
    $quickSearchInput.on('input', function () {
        if ($(this).val().length > 0) {
            $resetButton.css('display', 'block');
        } else {
            $resetButton.css('display', 'none');
        }
    });
    $quickSearchForm.on('submit', function (e) {
        e.preventDefault();
        quickSearch();
    });
    $resetButton.on('mouseup', function (e) {
        e.preventDefault();
        $quickSearchInput.val('');
        $searchArea.unmark();
    });
});

$(document).on('click', '.js-video-change', function(e){
    e.preventDefault();
    let $videoContainer = $('.video__frame'),
        $videos = $videoContainer.find('.dia-m-video-player'),
        $items = $('.binded-videos__list').find('.binded-videos__item'),
        $item = $(this).closest('.binded-videos__item'),
        videoId = ($item.length) ? $item.data('videoId') : $(this).data('videoId'),
        $targetVideo = $videoContainer.find('[data-video-id='+videoId+']');
    $videos.each(function (){
        $(this).hide().removeClass('dia-m-video-player--playing');
        let video = $(this).find('video').get(0);
        video.pause();
        // video.currentTime = 0;
    });
    $items.each(function (){
        $(this).removeClass('active');
    });
    $item.addClass('active');
    $targetVideo.css('display', 'flex').addClass('dia-m-video-player--playing');
    $targetVideo.find('video').get(0).play();
});

$(document).on('click', '.binded-videos__btn', function(){
    let $btn = $(this),
        $container = $btn.closest('.binded-videos__list'),
        text = $btn.text();
    $container.toggleClass('expanded');
    if (text == 'Показать все видео') {
        $btn.text('Свернуть все видео');
    } else {
        $btn.text('Показать все видео');
    }

});
/* End */
;
; /* Start:"a:4:{s:4:"full";s:47:"/embed/player/scripts/script.js?172715938411200";s:6:"source";s:31:"/embed/player/scripts/script.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/
const video = () => {
  const videos = document.querySelectorAll('.dia-m-video-player');
  if (!videos) return;

  const format = (s) => {
    let m = Math.floor(s / 60);
    m = (m >= 10) ? m : `0${m}`;
    s = Math.floor(s % 60);
    s = (s >= 10) ? s : `0${s}`;
    return `${m}:${s}`;
  }


  videos.forEach((item) => {
    item.classList.add('dia-m-video-player--loading');

    const v = item.querySelector('.dia-m-video-player__object');

    v.controls = false

    const playpause = item.querySelector('.dia-m-video-player__playpause');
    const mute = item.querySelector('.dia-m-video-player__mute');
    const volume = item.querySelector('.dia-m-video-player__volume');
    const progress = item.querySelector('.dia-m-video-player__progress');
    const fullscreen = item.querySelector('.dia-m-video-player__fullscreen');
    const timeElapsed = item.querySelector('.dia-m-video-player__time-elapsed');
    const timeTotal = item.querySelector('.dia-m-video-player__time-total');
    const settings = item.querySelector('.dia-m-video-player__settings');
    const settingsList = item.querySelector('.dia-m-video-player__settings-list');
    const pip = item.querySelector('.dia-m-video-player__pip');
    const share = item.querySelector('.dia-m-video-player__share');
    const shareButtons = share.querySelectorAll('.dia-m-video-player__share-item');
    const shareMessage = item.querySelector('.dia-m-video-player__share-message');
    const speed = item.querySelector('.dia-m-video-player__speed');
    const speedRate = speed.querySelectorAll('.dia-m-video-player__speed-item');
    const skip = item.querySelectorAll('.dia-m-video-player__skip');

    v.addEventListener('play', () => item.classList.add('dia-m-video-player--playing'));
    v.addEventListener('pause', () => item.classList.remove('dia-m-video-player--playing'));

    const setControls = () => {
      item.classList.remove('dia-m-video-player--loading');
      const changePlayState = () => {
        if (v.paused || v.ended) v.play();
        else v.pause();
      };

      const setRemoveControlsTimer = () => {
        window.removeControlsTimer = setTimeout(() => {
          item.classList.remove('dia-m-video-player--controls');
          item.removeEventListener('mouseup', setRemoveControlsTimer);
        }, 3000);
      };
      item.addEventListener('mousedown', (e) => {
        if (!e.target.closest('.dia-m-video-player__controls')
          && !e.target.closest('.dia-m-video-player__settings')
          && !e.target.closest('.dia-m-video-player__share')
          && !e.target.closest('.dia-m-video-player__speed')
        ) {
          if (window.innerWidth >= 1000) changePlayState();
          else {
            item.classList.toggle('dia-m-video-player--controls');
            item.addEventListener('mouseup', setRemoveControlsTimer);
          }
        } else if (window.innerWidth < 1000) {
          item.removeEventListener('mouseup', setRemoveControlsTimer);
          if (window.removeControlsTimer) clearTimeout(window.removeControlsTimer);
          item.addEventListener('mouseup', setRemoveControlsTimer);
        }
      });
      item.addEventListener('play', () => item.classList.remove('dia-m-video-player--controls'));
      playpause.addEventListener('click', changePlayState);
      window.addEventListener('keyup', (e) => {
        if (e.code === 'Space') changePlayState();
      })

      timeTotal.innerText = format(v.duration);
      timeElapsed.innerText = format(v.currentTime);
      progress.setAttribute('max', `${v.duration * 100}`);
      progress.style.setProperty('--gradient-point', `${(progress.value / progress.max) * 100}%`);

      v.addEventListener('timeupdate', () => {
        timeElapsed.innerText = format(v.currentTime);
        progress.value = v.currentTime * 100;
        progress.style.setProperty('--gradient-point', `${(progress.value / progress.max) * 100}%`);
      });

      progress.addEventListener('change', () => v.currentTime = progress.value / 100);
      progress.addEventListener('input', () => v.currentTime = progress.value / 100);

      document.addEventListener('fullscreenchange', () => {
        setFullscreenData(!!document.fullscreenElement);
      });

      const setFullscreenData = (state) => {
        if (!!state) {
          item.classList.add('dia-m-video-player--fullscreen');
        }
        else item.classList.remove('dia-m-video-player--fullscreen');
      }

      const handleFullscreen = () => {
        if (document.fullscreenElement !== undefined || document.webkitFullscreenElement !== undefined) {
          if (document.fullscreenElement !== null && document.webkitFullscreenElement !== null) {
            if (item.requestFullscreen) document.exitFullscreen();
            else if (item.webkitRequestFullscreen) document.webkitExitFullscreen();
            else if (item.msRequestFullscreen) document.msExitFullscreen();
            setFullscreenData(false);
          } else {
            if (item.requestFullscreen) item.requestFullscreen();
            else if (item.webkitRequestFullscreen) item.webkitRequestFullscreen();
            else if (item.msRequestFullscreen) item.msRequestFullscreen();
            setFullscreenData(true);
          }
        } else {
          v.webkitSetPresentationMode("fullscreen");
        }
      }

      fullscreen.addEventListener('click', () => handleFullscreen());

      volume.value = v.volume * 100;
      volume.style.setProperty('--gradient-point', `${volume.value}%`);

      const changeVolume = (i) => {
        v.volume = i.target.value / 100;
        if (v.volume === 0) item.classList.add('dia-m-video-player--muted');
        else if (item.classList.contains('dia-m-video-player--muted')) item.classList.remove('dia-m-video-player--muted');
        if (v.muted) v.muted = false;
        volume.style.setProperty('--gradient-point', `${i.target.value}%`);
      };

      volume.addEventListener('change', changeVolume);
      volume.addEventListener('input', changeVolume);
      mute.addEventListener('click', () => {
        v.muted = !v.muted;
        if (v.muted) item.classList.add('dia-m-video-player--muted');
        else if (item.classList.contains('dia-m-video-player--muted')) item.classList.remove('dia-m-video-player--muted');
        volume.value = v.muted ? 0 : v.volume * 100;
        volume.style.setProperty('--gradient-point', `${volume.value}%`);
      });

      settings.addEventListener('click', (e) => {
        const closeSettings = () => {
          item.classList.remove('dia-m-video-player--settings');
          window.removeEventListener('click', closeSettings);
        };
        if (e.target.classList.contains('dia-m-video-player__settings-open')) item.classList.toggle('dia-m-video-player--settings');
        setTimeout(() => {
          if (item.classList.contains('dia-m-video-player--settings')) window.addEventListener('click', closeSettings)
        }, 100);
      })

      share.addEventListener('click', (e) => {
        const closeShare = () => {
          item.classList.remove('dia-m-video-player--share');
          window.removeEventListener('click', closeShare);
        };
        if (e.target.classList.contains('dia-m-video-player__share-open')) item.classList.toggle('dia-m-video-player--share');
        setTimeout(() => {
          if (item.classList.contains('dia-m-video-player--share')) window.addEventListener('click', closeShare)
        }, 100);
      })

      if (!v.requestPictureInPicture) pip.remove();
      if (settingsList.children.length === 0) settings.remove();
      pip.setAttribute('disabled', 'disabled');
      v.addEventListener('loadeddata', () => pip.removeAttribute('disabled'));
      pip.addEventListener('click', () => {
        if (document.pictureInPictureElement) document.exitPictureInPicture();
        else if (document.pictureInPictureEnabled) v.requestPictureInPicture();
      });

      const messages = {
        link: 'Ссылка скопирована',
        embed: 'Код для вставки скопирован',
      };

      shareButtons.forEach((button) => {
        button.addEventListener('click', (e) => {
          navigator.clipboard.writeText(e.currentTarget.dataset.content);
          shareMessage.innerText = messages[e.currentTarget.dataset.type];
          shareMessage.classList.add('dia-m-video-player__share-message--active');
          window.hideShareMessage = setTimeout(() => {
            shareMessage.classList.remove('dia-m-video-player__share-message--active');
          }, 3000);
        })
      });

      speed.addEventListener('click', (e) => {
        const closeSpeed = () => {
          item.classList.remove('dia-m-video-player--speed');
          window.removeEventListener('click', closeSpeed);
        };
        if (e.target.classList.contains('dia-m-video-player__speed-open')) item.classList.toggle('dia-m-video-player--speed');
        setTimeout(() => {
          if (item.classList.contains('dia-m-video-player--speed')) window.addEventListener('click', closeSpeed)
        }, 100);
      });
      speedRate.forEach((speedRateItem) => {
        speedRateItem.addEventListener('change', (e) => {
          v.playbackRate = +e.target.value;
        });
      });

      const onSkip = (e) => {
        const timeToSkip = 5;
        const playbackSpeed = 4;
        const started = Date.now();
        const currentSpeed = v.playbackRate;
        const isPaused = !!v.paused;
        const isMuted = !!v.muted

        let skipDirection;
        if (e.target.classList.contains('dia-m-video-player__skip--forward')) skipDirection = 1;
        else if (e.target.classList.contains('dia-m-video-player__skip--back')) skipDirection = -1;

        const onSkipTimer = setTimeout(() => {
          if (e.target.classList.contains('dia-m-video-player__skip--forward')) {
            v.playbackRate = playbackSpeed;
            if (!isMuted) v.muted = true;
            if (isPaused) v.play();
          } else if (e.target.classList.contains('dia-m-video-player__skip--back')) {
            window.intervalRewind = setInterval(function(){
              if (v.currentTime === 0) {
                clearInterval(intervalRewind);
                v.pause();
              } else {
                v.currentTime -= .4;
              }
            },100);
          }

        }, 1000)
        const onSkipEnd = () => {
          const now = Date.now();
          if (now - started < 1000) v.currentTime = v.currentTime + (timeToSkip * skipDirection);
          else {
            v.playbackRate = currentSpeed;
            if (!isMuted) v.muted = false;
            if (isPaused) v.pause();
          }
          clearTimeout(onSkipTimer);
          if (window.intervalRewind) clearInterval(window.intervalRewind);
          e.target.removeEventListener('mouseup', onSkipEnd);
        };
        e.target.addEventListener('mouseup', onSkipEnd);
      }

      skip.forEach((skipButton) => skipButton.addEventListener('mousedown', onSkip));
    };

    v.addEventListener('loadedmetadata', setControls);
  });

};

document.addEventListener("DOMContentLoaded", function (event) {
  video();
});

/* End */
;
; /* Start:"a:4:{s:4:"full";s:89:"/local/templates/diam/components/bitrix/catalog.section/new_cat/script.js?172715939560985";s:6:"source";s:73:"/local/templates/diam/components/bitrix/catalog.section/new_cat/script.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/
function on_resize_textbtn(){
    var text_par = $('.kd-show-title-btn');
    if(!text_par.hasClass('full-text')) {
        var name_div = $('.kd-last_viewed_items').find('.name_div');
        var display_toogle_btn = false;
        name_div.each(function () {
            var width_name_div = $(this);
            var width_a_div = $(this).find('a');
            if (width_a_div.length) {
                if (width_a_div.width() > width_name_div.width()) display_toogle_btn = true;
            }
        });
        var text = text_par.find('.kd-collapse-text');
        if (display_toogle_btn) {
            text.removeClass('kd-hide');
        } else {
            text.addClass('kd-hide');
        }
    }
}
function mobile_textbtn() {
    var text_par = $('.kd-show-title-btn');
    if (window.innerWidth < 1025) {
        text_par.addClass('full-text');
        text_par.find('.kd-collapse-text').removeClass('kd-hide').text('Названия в одну строку');
        $('.kd-last_viewed_items').addClass('show-title-full');
    }
}

(function (window) {

    function addParameterToURL(param){
        _url = location.href;
        _url += (_url.split('?')[1] ? '&':'?') + param;
        return _url;
    }

    if (!!window.JCCatalogSectionViewed)
    {
        return;
    }

    var BasketButton = function(params)
    {
        BasketButton.superclass.constructor.apply(this, arguments);
        this.nameNode = BX.create('span', {
            props : { className : 'btn btn_lilac btn_shadow', id : this.id },
            text: params.text
        });
        this.buttonNode = BX.create('span', {
            attrs: { className: params.ownerClass },
            style: { marginBottom: '0', borderBottom: '0 none transparent' },
            children: [this.nameNode],
            events : this.contextEvents
        });
        if (BX.browser.IsIE())
        {
            this.buttonNode.setAttribute("hideFocus", "hidefocus");
        }
    };
    BX.extend(BasketButton, BX.PopupWindowButton);

    window.JCCatalogSectionViewed = function (arParams)
    {
        this.productType = 0;
        this.showQuantity = true;
        this.showAbsent = true;
        this.secondPict = false;
        this.showOldPrice = false;
        this.showPercent = false;
        this.showSkuProps = false;
        this.visual = {
            ID: '',
            /*PICT_ID: '',
            SECOND_PICT_ID: '',*/
            QUANTITY_ID: '',
            QUANTITY_UP_ID: '',
            QUANTITY_DOWN_ID: '',
            /*PRICE_ID: '',*/
            DSC_PERC: '',
            SECOND_DSC_PERC: '',
            DISPLAY_PROP_DIV: '',
            /*BASKET_PROP_DIV: ''*/
        };
        this.product = {
            checkQuantity: false,
            maxQuantity: 0,
            stepQuantity: 1,
            isDblQuantity: false,
            canBuy: true,
            canSubscription: true,
            name: '',
            pict: {},
            id: 0,
            addUrl: '',
            buyUrl: ''
        };
        this.basketData = {
            useProps: false,
            emptyProps: false,
            quantity: 'quantity',
            props: 'prop',
            reserveReqProp: 'RESERVE_REQ',
            basketUrl: ''
        };

        this.defaultPict = {
            pict: null,
            secondPict: null
        };

        this.checkQuantity = false;
        this.maxQuantity = 0;
        this.stepQuantity = 1;
        this.isDblQuantity = false;
        this.canBuy = true;
        this.canSubscription = true;
        this.precision = 6;
        this.precisionFactor = Math.pow(10,this.precision);

        this.offers = [];
        this.offerNum = 0;
        this.treeProps = [];
        this.obTreeRows = [];
        this.showCount = [];
        this.showStart = [];
        this.selectedValues = {};

        this.obProduct = null;
        this.obQuantity = null;
        this.obQuantityUp = null;
        this.obQuantityDown = null;
        this.obPict = null;
        this.obSecondPict = null;
        this.obPrice = null;
        this.obTree = null;
        this.obBuyBtn = null;
        this.obDscPerc = null;
        this.obSecondDscPerc = null;
        this.obSkuProps = null;
        this.obMeasure = null;

        this.obPopupWin = null;
        this.basketUrl = '';
        this.basketParams = {};

        this.treeRowShowSize = 5;
        this.treeEnableArrow = { display: '', cursor: 'pointer', opacity: 1 };
        this.treeDisableArrow = { display: '', cursor: 'default', opacity:0.2 };

        this.lastElement = false;
        this.containerHeight = 0;

        this.errorCode = 0;

        if ('object' === typeof arParams)
        {
            this.productType = parseInt(arParams.PRODUCT_TYPE, 10);
            this.showQuantity = arParams.SHOW_QUANTITY;
            this.showAbsent = arParams.SHOW_ABSENT;
            this.secondPict = !!arParams.SECOND_PICT;
            this.showOldPrice = !!arParams.SHOW_OLD_PRICE;
            this.showPercent = !!arParams.SHOW_DISCOUNT_PERCENT;
            this.showSkuProps = !!arParams.SHOW_SKU_PROPS;
            this.product.reserveReq = arParams.PRODUCT.RESERVE_REQ;
            this.visual = arParams.VISUAL;
            switch (this.productType)
            {
                case 1://product
                case 2://set
                    if (!!arParams.PRODUCT && 'object' === typeof(arParams.PRODUCT))
                    {
                        if (this.showQuantity)
                        {
                            this.product.checkQuantity = arParams.PRODUCT.CHECK_QUANTITY;
                            this.product.isDblQuantity = arParams.PRODUCT.QUANTITY_FLOAT;
                            if (this.product.checkQuantity)
                            {
                                this.product.maxQuantity = (this.product.isDblQuantity ? parseFloat(arParams.PRODUCT.MAX_QUANTITY) : parseInt(arParams.PRODUCT.MAX_QUANTITY, 10));
                            }
                            this.product.stepQuantity = (this.product.isDblQuantity ? parseFloat(arParams.PRODUCT.STEP_QUANTITY) : parseInt(arParams.PRODUCT.STEP_QUANTITY, 10));

                            this.checkQuantity = this.product.checkQuantity;
                            this.isDblQuantity = this.product.isDblQuantity;
                            this.maxQuantity = this.product.maxQuantity;
                            this.stepQuantity = this.product.stepQuantity;
                            if (this.isDblQuantity)
                            {
                                this.stepQuantity = Math.round(this.stepQuantity*this.precisionFactor)/this.precisionFactor;
                            }
                        }
                        this.product.canBuy = arParams.PRODUCT.CAN_BUY;
                        this.product.canSubscription = arParams.PRODUCT.SUBSCRIPTION;

                        this.canBuy = this.product.canBuy;
                        this.canSubscription = this.product.canSubscription;

                        this.product.name = arParams.PRODUCT.NAME;
                        this.product.pict = arParams.PRODUCT.PICT;
                        this.product.id = arParams.PRODUCT.ID;
                        if (!!arParams.PRODUCT.ADD_URL)
                        {
                            this.product.addUrl = arParams.PRODUCT.ADD_URL;
                        }
                        if (!!arParams.PRODUCT.BUY_URL)
                        {
                            this.product.buyUrl = arParams.PRODUCT.BUY_URL;
                        }
                        if (!!arParams.BASKET && 'object' === typeof(arParams.BASKET))
                        {
                            this.basketData.useProps = !!arParams.BASKET.ADD_PROPS;
                            this.basketData.emptyProps = !!arParams.BASKET.EMPTY_PROPS;
                        }
                    }
                    else
                    {
                        this.errorCode = -1;
                    }
                    break;
                case 3://sku
                    if (!!arParams.OFFERS && BX.type.isArray(arParams.OFFERS))
                    {
                        if (!!arParams.PRODUCT && 'object' === typeof(arParams.PRODUCT))
                        {
                            this.product.name = arParams.PRODUCT.NAME;
                            this.product.id = arParams.PRODUCT.ID;
                        }
                        this.offers = arParams.OFFERS;
                        this.offerNum = 0;
                        if (!!arParams.OFFER_SELECTED)
                        {
                            this.offerNum = parseInt(arParams.OFFER_SELECTED, 10);
                        }
                        if (isNaN(this.offerNum))
                        {
                            this.offerNum = 0;
                        }
                        if (!!arParams.TREE_PROPS)
                        {
                            this.treeProps = arParams.TREE_PROPS;
                        }
                        if (!!arParams.DEFAULT_PICTURE)
                        {
                            this.defaultPict.pict = arParams.DEFAULT_PICTURE.PICTURE;
                            this.defaultPict.secondPict = arParams.DEFAULT_PICTURE.PICTURE_SECOND;
                        }
                    }
                    else
                    {
                        this.errorCode = -1;
                    }
                    break;
                default:
                    this.errorCode = -1;
            }
            if (!!arParams.BASKET && 'object' === typeof(arParams.BASKET))
            {
                if (!!arParams.BASKET.QUANTITY)
                {
                    this.basketData.quantity = arParams.BASKET.QUANTITY;
                }
                if (!!arParams.BASKET.PROPS)
                {
                    this.basketData.props = arParams.BASKET.PROPS;
                }
                if (!!arParams.BASKET.BASKET_URL)
                {
                    this.basketData.basketUrl = arParams.BASKET.BASKET_URL;
                }
            }
            this.lastElement = (!!arParams.LAST_ELEMENT && 'Y' === arParams.LAST_ELEMENT);
        }
        if (0 === this.errorCode)
        {
            BX.ready(BX.delegate(this.Init,this));
        }
    };

    window.JCCatalogSectionViewed.prototype.Init = function()
    {
        var i = 0,
            strPrefix = '',
            TreeItems = null;

        this.obProduct = BX(this.visual.ID);
        if (!this.obProduct)
        {
            this.errorCode = -1;
        }
        /*	this.obPict = BX(this.visual.PICT_ID);
            if (!this.obPict)
            {
                this.errorCode = -2;
            }
            if (this.secondPict && !!this.visual.SECOND_PICT_ID)
            {
                this.obSecondPict = BX(this.visual.SECOND_PICT_ID);
            }*/
        /*	this.obPrice = BX(this.visual.PRICE_ID);
            if (!this.obPrice)
            {
                this.errorCode = -16;
            }*/
        if (this.showQuantity && !!this.visual.QUANTITY_ID)
        {
            this.obQuantity = BX(this.visual.QUANTITY_ID);
            if (!!this.visual.QUANTITY_UP_ID)
            {
                this.obQuantityUp = BX(this.visual.QUANTITY_UP_ID);
            }
            if (!!this.visual.QUANTITY_DOWN_ID)
            {
                this.obQuantityDown = BX(this.visual.QUANTITY_DOWN_ID);
            }
        }
        if (3 === this.productType)
        {
            if (!!this.visual.TREE_ID)
            {
                this.obTree = BX(this.visual.TREE_ID);
                if (!this.obTree)
                {
                    this.errorCode = -256;
                }
                strPrefix = this.visual.TREE_ITEM_ID;
                for (i = 0; i < this.treeProps.length; i++)
                {
                    this.obTreeRows[i] = {
                        LEFT: BX(strPrefix+this.treeProps[i].ID+'_left'),
                        RIGHT: BX(strPrefix+this.treeProps[i].ID+'_right'),
                        LIST: BX(strPrefix+this.treeProps[i].ID+'_list'),
                        CONT: BX(strPrefix+this.treeProps[i].ID+'_cont')
                    };
                    if (!this.obTreeRows[i].LEFT || !this.obTreeRows[i].RIGHT || !this.obTreeRows[i].LIST || !this.obTreeRows[i].CONT)
                    {
                        this.errorCode = -512;
                        break;
                    }
                }
            }
            if (!!this.visual.QUANTITY_MEASURE)
            {
                this.obMeasure = BX(this.visual.QUANTITY_MEASURE);
            }
        }
        if (!!this.visual.BUY_ID)
        {
            this.obBuyBtn = BX(this.visual.BUY_ID);
        }

        if (this.showPercent)
        {
            if (!!this.visual.DSC_PERC)
            {
                this.obDscPerc = BX(this.visual.DSC_PERC);
            }
            if (this.secondPict && !!this.visual.SECOND_DSC_PERC)
            {
                this.obSecondDscPerc = BX(this.visual.SECOND_DSC_PERC);
            }
        }

        if (this.showSkuProps)
        {
            if (!!this.visual.DISPLAY_PROP_DIV)
            {
                this.obSkuProps = BX(this.visual.DISPLAY_PROP_DIV);
            }
        }

        if (0 === this.errorCode)
        {
            if (this.showQuantity)
            {
                if (!!this.obQuantityUp)
                {
                    BX.bind(this.obQuantityUp, 'click', BX.delegate(this.QuantityUp, this));
                }
                if (!!this.obQuantityDown)
                {
                    BX.bind(this.obQuantityDown, 'click', BX.delegate(this.QuantityDown, this));
                }
                if (!!this.obQuantity)
                {
                    BX.bind(this.obQuantity, 'change', BX.delegate(this.QuantityChange, this));
                }
            }
            switch (this.productType)
            {
                case 1://product
                    break;
                case 3://sku
                    TreeItems = BX.findChildren(this.obTree, {tagName: 'li'}, true);
                    if (!!TreeItems && 0 < TreeItems.length)
                    {
                        for (i = 0; i < TreeItems.length; i++)
                        {
                            BX.bind(TreeItems[i], 'click', BX.delegate(this.SelectOfferProp, this));
                        }
                    }
                    for (i = 0; i < this.obTreeRows.length; i++)
                    {
                        BX.bind(this.obTreeRows[i].LEFT, 'click', BX.delegate(this.RowLeft, this));
                        BX.bind(this.obTreeRows[i].RIGHT, 'click', BX.delegate(this.RowRight, this));
                    }
                    this.SetCurrent();
                    break;
            }
            if (!!this.obBuyBtn)
            {
                BX.bind(this.obBuyBtn, 'click', BX.delegate(this.Basket, this));
            }
        }
    };

    window.JCCatalogSectionViewed.prototype.checkHeight = function()
    {
        this.containerHeight = parseInt(this.obProduct.parentNode.offsetHeight, 10);
        if (isNaN(this.containerHeight))
        {
            this.containerHeight = 0;
        }
    };


    window.JCCatalogSectionViewed.prototype.clearHeight = function()
    {
        BX.adjust(this.obProduct.parentNode, {style: { height: 'auto'}});
    };

    window.JCCatalogSectionViewed.prototype.QuantityUp = function()
    {

        var curValue = 0,
            boolSet = true;

        if (0 === this.errorCode && this.showQuantity && this.canBuy)
        {
            curValue = (this.isDblQuantity ? parseFloat(this.obQuantity.value) : parseInt(this.obQuantity.value, 10));
            if (!isNaN(curValue))
            {
                curValue += this.stepQuantity;
                if (this.checkQuantity)
                {
                    if (curValue > this.maxQuantity)
                    {
                        boolSet = false;
                    }
                }
                if (boolSet)
                {
                    if (this.isDblQuantity)
                    {
                        curValue = Math.round(curValue*this.precisionFactor)/this.precisionFactor;
                    }
                    this.obQuantity.value = curValue;
                }
            }
        }
    };

    window.JCCatalogSectionViewed.prototype.QuantityDown = function()
    {
        var curValue = 0,
            boolSet = true;

        if (0 === this.errorCode && this.showQuantity && this.canBuy)
        {
            curValue = (this.isDblQuantity ? parseFloat(this.obQuantity.value): parseInt(this.obQuantity.value, 10));
            if (!isNaN(curValue))
            {
                curValue -= this.stepQuantity;
                if (curValue < this.stepQuantity)
                {
                    boolSet = false;
                }
                if (boolSet)
                {
                    if (this.isDblQuantity)
                    {
                        curValue = Math.round(curValue*this.precisionFactor)/this.precisionFactor;
                    }
                    this.obQuantity.value = curValue;
                }
            }
        }
    };

    window.JCCatalogSectionViewed.prototype.QuantityChange = function()
    {
        var curValue = 0,
            boolSet = true;

        if (0 === this.errorCode && this.showQuantity)
        {
            if (this.canBuy)
            {
                curValue = (this.isDblQuantity ? parseFloat(this.obQuantity.value) : parseInt(this.obQuantity.value, 10));
                if (!isNaN(curValue))
                {
                    if (this.checkQuantity)
                    {
                        if (curValue > this.maxQuantity)
                        {
                            boolSet = false;
                            curValue = this.maxQuantity;
                        }
                        else if (curValue < this.stepQuantity)
                        {
                            boolSet = false;
                            curValue = this.stepQuantity;
                        }
                    }
                    if (!boolSet)
                    {
                        this.obQuantity.value = curValue;
                    }
                }
                else
                {
                    this.obQuantity.value = this.stepQuantity;
                }
            }
            else
            {
                this.obQuantity.value = this.stepQuantity;
            }
        }
    };

    window.JCCatalogSectionViewed.prototype.QuantitySet = function(index)
    {
        if (0 === this.errorCode)
        {
            this.canBuy = this.offers[index].CAN_BUY;
            if (this.canBuy)
            {
                BX.addClass(this.obBuyBtn, 'bx_bt_button');
                BX.removeClass(this.obBuyBtn, 'bx_bt_button_type_2');
                this.obBuyBtn.innerHTML = BX.message('CVP_MESS_BTN_BUY');
            }
            else
            {
                BX.addClass(this.obBuyBtn, 'bx_bt_button_type_2');
                BX.removeClass(this.obBuyBtn, 'bx_bt_button');
                this.obBuyBtn.innerHTML = BX.message('CVP_MESS_NOT_AVAILABLE');
            }
            if (this.showQuantity)
            {
                this.isDblQuantity = this.offers[index].QUANTITY_FLOAT;
                this.checkQuantity = this.offers[index].CHECK_QUANTITY;
                if (this.isDblQuantity)
                {
                    this.maxQuantity = parseFloat(this.offers[index].MAX_QUANTITY);
                    this.stepQuantity = Math.round(parseFloat(this.offers[index].STEP_QUANTITY)*this.precisionFactor)/this.precisionFactor;
                }
                else
                {
                    this.maxQuantity = parseInt(this.offers[index].MAX_QUANTITY, 10);
                    this.stepQuantity = parseInt(this.offers[index].STEP_QUANTITY, 10);
                }

                this.obQuantity.value = this.stepQuantity;
                this.obQuantity.disabled = !this.canBuy;
                if (!!this.obMeasure)
                {
                    if (!!this.offers[index].MEASURE)
                    {
                        BX.adjust(this.obMeasure, { html : this.offers[index].MEASURE});
                    }
                    else
                    {
                        BX.adjust(this.obMeasure, { html : ''});
                    }
                }
            }
        }
    };

    window.JCCatalogSectionViewed.prototype.SelectOfferProp = function()
    {
        var i = 0,
            value = '',
            strTreeValue = '',
            arTreeItem = [],
            RowItems = null,
            target = BX.proxy_context;

        if (!!target && target.hasAttribute('data-treevalue'))
        {
            strTreeValue = target.getAttribute('data-treevalue');
            arTreeItem = strTreeValue.split('_');
            if (this.SearchOfferPropIndex(arTreeItem[0], arTreeItem[1]))
            {
                RowItems = BX.findChildren(target.parentNode, {tagName: 'li'}, false);
                if (!!RowItems && 0 < RowItems.length)
                {
                    for (i = 0; i < RowItems.length; i++)
                    {
                        value = RowItems[i].getAttribute('data-onevalue');
                        if (value === arTreeItem[1])
                        {
                            BX.addClass(RowItems[i], 'bx_active');
                        }
                        else
                        {
                            BX.removeClass(RowItems[i], 'bx_active');
                        }
                    }
                }
            }
        }
    };

    window.JCCatalogSectionViewed.prototype.SearchOfferPropIndex = function(strPropID, strPropValue)
    {
        var strName = '',
            arShowValues = false,
            i, j,
            arCanBuyValues = [],
            index = -1,
            arFilter = {},
            tmpFilter = [];

        for (i = 0; i < this.treeProps.length; i++)
        {
            if (this.treeProps[i].ID === strPropID)
            {
                index = i;
                break;
            }
        }

        if (-1 < index)
        {
            for (i = 0; i < index; i++)
            {
                strName = 'PROP_'+this.treeProps[i].ID;
                arFilter[strName] = this.selectedValues[strName];
            }
            strName = 'PROP_'+this.treeProps[index].ID;
            arShowValues = this.GetRowValues(arFilter, strName);
            if (!arShowValues)
            {
                return false;
            }
            if (!BX.util.in_array(strPropValue, arShowValues))
            {
                return false;
            }
            arFilter[strName] = strPropValue;
            for (i = index+1; i < this.treeProps.length; i++)
            {
                strName = 'PROP_'+this.treeProps[i].ID;
                arShowValues = this.GetRowValues(arFilter, strName);
                if (!arShowValues)
                {
                    return false;
                }
                if (this.showAbsent)
                {
                    arCanBuyValues = [];
                    tmpFilter = [];
                    tmpFilter = BX.clone(arFilter, true);
                    for (j = 0; j < arShowValues.length; j++)
                    {
                        tmpFilter[strName] = arShowValues[j];
                        if (this.GetCanBuy(tmpFilter))
                        {
                            arCanBuyValues[arCanBuyValues.length] = arShowValues[j];
                        }
                    }
                }
                else
                {
                    arCanBuyValues = arShowValues;
                }
                if (!!this.selectedValues[strName] && BX.util.in_array(this.selectedValues[strName], arCanBuyValues))
                {
                    arFilter[strName] = this.selectedValues[strName];
                }
                else
                {
                    arFilter[strName] = arCanBuyValues[0];
                }
                this.UpdateRow(i, arFilter[strName], arShowValues, arCanBuyValues);
            }
            this.selectedValues = arFilter;
            this.ChangeInfo();
        }
        return true;
    };

    window.JCCatalogSectionViewed.prototype.RowLeft = function()
    {
        var i = 0,
            strTreeValue = '',
            index = -1,
            target = BX.proxy_context;

        if (!!target && target.hasAttribute('data-treevalue'))
        {
            strTreeValue = target.getAttribute('data-treevalue');
            for (i = 0; i < this.treeProps.length; i++)
            {
                if (this.treeProps[i].ID === strTreeValue)
                {
                    index = i;
                    break;
                }
            }
            if (-1 < index && this.treeRowShowSize < this.showCount[index])
            {
                if (0 > this.showStart[index])
                {
                    this.showStart[index]++;
                    BX.adjust(this.obTreeRows[index].LIST, { style: { marginLeft: this.showStart[index]*20+'%' }});
                    BX.adjust(this.obTreeRows[index].RIGHT, { style: this.treeEnableArrow });
                }

                if (0 <= this.showStart[index])
                {
                    BX.adjust(this.obTreeRows[index].LEFT, { style: this.treeDisableArrow });
                }
            }
        }
    };

    window.JCCatalogSectionViewed.prototype.RowRight = function()
    {
        var i = 0,
            strTreeValue = '',
            index = -1,
            target = BX.proxy_context;

        if (!!target && target.hasAttribute('data-treevalue'))
        {
            strTreeValue = target.getAttribute('data-treevalue');
            for (i = 0; i < this.treeProps.length; i++)
            {
                if (this.treeProps[i].ID === strTreeValue)
                {
                    index = i;
                    break;
                }
            }
            if (-1 < index && this.treeRowShowSize < this.showCount[index])
            {
                if ((this.treeRowShowSize - this.showStart[index]) < this.showCount[index])
                {
                    this.showStart[index]--;
                    BX.adjust(this.obTreeRows[index].LIST, { style: { marginLeft: this.showStart[index]*20+'%' }});
                    BX.adjust(this.obTreeRows[index].LEFT, { style: this.treeEnableArrow });
                }

                if ((this.treeRowShowSize - this.showStart[index]) >= this.showCount[index])
                {
                    BX.adjust(this.obTreeRows[index].RIGHT, { style: this.treeDisableArrow });
                }
            }
        }
    };

    window.JCCatalogSectionViewed.prototype.UpdateRow = function(intNumber, activeID, showID, canBuyID)
    {
        var i = 0,
            showI = 0,
            value = '',
            countShow = 0,
            strNewLen = '',
            obData = {},
            pictMode = false,
            extShowMode = false,
            isCurrent = false,
            selectIndex = 0,
            obLeft = this.treeEnableArrow,
            obRight = this.treeEnableArrow,
            currentShowStart = 0,
            RowItems = null;

        if (-1 < intNumber && intNumber < this.obTreeRows.length)
        {
            RowItems = BX.findChildren(this.obTreeRows[intNumber].LIST, {tagName: 'li'}, false);
            if (!!RowItems && 0 < RowItems.length)
            {
                pictMode = ('PICT' === this.treeProps[intNumber].SHOW_MODE);
                countShow = showID.length;
                extShowMode = this.treeRowShowSize < countShow;
                strNewLen = (extShowMode ? (100/countShow)+'%' : '20%');
                obData = {
                    props: { className: '' },
                    style: {
                        width: strNewLen
                    }
                };
                if (pictMode)
                {
                    obData.style.paddingTop = strNewLen;
                }
                for (i = 0; i < RowItems.length; i++)
                {
                    value = RowItems[i].getAttribute('data-onevalue');
                    isCurrent = (value === activeID);
                    if (BX.util.in_array(value, canBuyID))
                    {
                        obData.props.className = (isCurrent ? 'bx_active' : '');
                    }
                    else
                    {
                        obData.props.className = (isCurrent ? 'bx_active bx_missing' : 'bx_missing');
                    }
                    obData.style.display = 'none';
                    if (BX.util.in_array(value, showID))
                    {
                        obData.style.display = '';
                        if (isCurrent)
                        {
                            selectIndex = showI;
                        }
                        showI++;
                    }
                    BX.adjust(RowItems[i], obData);
                }

                obData = {
                    style: {
                        width: (extShowMode ? 20*countShow : 100)+'%',
                        marginLeft: '0%'
                    }
                };
                if (pictMode)
                {
                    BX.adjust(this.obTreeRows[intNumber].CONT, {props: {className: (extShowMode ? 'bx_item_detail_scu full' : 'bx_item_detail_scu')}});
                }
                else
                {
                    BX.adjust(this.obTreeRows[intNumber].CONT, {props: {className: (extShowMode ? 'bx_item_detail_size full' : 'bx_item_detail_size')}});
                }
                if (extShowMode)
                {
                    if (selectIndex +1 === countShow)
                    {
                        obRight = this.treeDisableArrow;
                    }
                    if (this.treeRowShowSize <= selectIndex)
                    {
                        currentShowStart = this.treeRowShowSize - selectIndex - 1;
                        obData.style.marginLeft = currentShowStart*20+'%';
                    }
                    if (0 === currentShowStart)
                    {
                        obLeft = this.treeDisableArrow;
                    }
                    BX.adjust(this.obTreeRows[intNumber].LEFT, {style: obLeft });
                    BX.adjust(this.obTreeRows[intNumber].RIGHT, {style: obRight });
                }
                else
                {
                    BX.adjust(this.obTreeRows[intNumber].LEFT, {style: {display: 'none'}});
                    BX.adjust(this.obTreeRows[intNumber].RIGHT, {style: {display: 'none'}});
                }
                BX.adjust(this.obTreeRows[intNumber].LIST, obData);
                this.showCount[intNumber] = countShow;
                this.showStart[intNumber] = currentShowStart;
            }
        }
    };

    window.JCCatalogSectionViewed.prototype.GetRowValues = function(arFilter, index)
    {
        var i = 0,
            j,
            arValues = [],
            boolSearch = false,
            boolOneSearch = true;

        if (0 === arFilter.length)
        {
            for (i = 0; i < this.offers.length; i++)
            {
                if (!BX.util.in_array(this.offers[i].TREE[index], arValues))
                {
                    arValues[arValues.length] = this.offers[i].TREE[index];
                }
            }
            boolSearch = true;
        }
        else
        {
            for (i = 0; i < this.offers.length; i++)
            {
                boolOneSearch = true;
                for (j in arFilter)
                {
                    if (arFilter[j] !== this.offers[i].TREE[j])
                    {
                        boolOneSearch = false;
                        break;
                    }
                }
                if (boolOneSearch)
                {
                    if (!BX.util.in_array(this.offers[i].TREE[index], arValues))
                    {
                        arValues[arValues.length] = this.offers[i].TREE[index];
                    }
                    boolSearch = true;
                }
            }
        }
        return (boolSearch ? arValues : false);
    };

    window.JCCatalogSectionViewed.prototype.GetCanBuy = function(arFilter)
    {
        var i = 0,
            j,
            boolSearch = false,
            boolOneSearch = true;

        for (i = 0; i < this.offers.length; i++)
        {
            boolOneSearch = true;
            for (j in arFilter)
            {
                if (arFilter[j] !== this.offers[i].TREE[j])
                {
                    boolOneSearch = false;
                    break;
                }
            }
            if (boolOneSearch)
            {
                if (this.offers[i].CAN_BUY)
                {
                    boolSearch = true;
                    break;
                }
            }
        }
        return boolSearch;
    };

    window.JCCatalogSectionViewed.prototype.SetCurrent = function()
    {
        var i = 0,
            j = 0,
            arCanBuyValues = [],
            strName = '',
            arShowValues = false,
            arFilter = {},
            tmpFilter = [],
            current = this.offers[this.offerNum].TREE;

        for (i = 0; i < this.treeProps.length; i++)
        {
            strName = 'PROP_'+this.treeProps[i].ID;
            arShowValues = this.GetRowValues(arFilter, strName);
            if (!arShowValues)
            {
                break;
            }
            if (BX.util.in_array(current[strName], arShowValues))
            {
                arFilter[strName] = current[strName];
            }
            else
            {
                arFilter[strName] = arShowValues[0];
                this.offerNum = 0;
            }
            if (this.showAbsent)
            {
                arCanBuyValues = [];
                tmpFilter = [];
                tmpFilter = BX.clone(arFilter, true);
                for (j = 0; j < arShowValues.length; j++)
                {
                    tmpFilter[strName] = arShowValues[j];
                    if (this.GetCanBuy(tmpFilter))
                    {
                        arCanBuyValues[arCanBuyValues.length] = arShowValues[j];
                    }
                }
            }
            else
            {
                arCanBuyValues = arShowValues;
            }
            this.UpdateRow(i, arFilter[strName], arShowValues, arCanBuyValues);
        }
        this.selectedValues = arFilter;
        this.ChangeInfo();
    };

    window.JCCatalogSectionViewed.prototype.ChangeInfo = function()
    {
        var i = 0,
            j,
            index = -1,
            obData = {},
            boolOneSearch = true,
            strPrice = '';

        for (i = 0; i < this.offers.length; i++)
        {
            boolOneSearch = true;
            for (j in this.selectedValues)
            {
                if (this.selectedValues[j] !== this.offers[i].TREE[j])
                {
                    boolOneSearch = false;
                    break;
                }
            }
            if (boolOneSearch)
            {
                index = i;
                break;
            }
        }
        if (-1 < index)
        {
            if (!!this.obPict)
            {
                if (!!this.offers[index].PREVIEW_PICTURE)
                {
                    BX.adjust(this.obPict, {style: {backgroundImage: 'url('+this.offers[index].PREVIEW_PICTURE.SRC+')'}});
                }
                else
                {
                    BX.adjust(this.obPict, {style: {backgroundImage: 'url('+this.defaultPict.pict.SRC+')'}});
                }
            }
            if (this.secondPict && !!this.obSecondPict)
            {
                if (!!this.offers[index].PREVIEW_PICTURE_SECOND)
                {
                    BX.adjust(this.obSecondPict, {style: {backgroundImage: 'url('+this.offers[index].PREVIEW_PICTURE_SECOND.SRC+')'}});
                }
                else if (!!this.offers[index].PREVIEW_PICTURE.SRC)
                {
                    BX.adjust(this.obSecondPict, {style: {backgroundImage: 'url('+this.offers[index].PREVIEW_PICTURE.SRC+')'}});
                }
                else if (!!this.defaultPict.secondPict)
                {
                    BX.adjust(this.obSecondPict, {style: {backgroundImage: 'url('+this.defaultPict.secondPict.SRC+')'}});
                }
                else
                {
                    BX.adjust(this.obSecondPict, {style: {backgroundImage: 'url('+this.defaultPict.pict.SRC+')'}});
                }
            }
            if (this.showSkuProps && !!this.obSkuProps)
            {
                if (0 === this.offers[index].DISPLAY_PROPERTIES.length)
                {
                    BX.adjust(this.obSkuProps, {style: {display: 'none'}, html: ''});
                }
                else
                {
                    BX.adjust(this.obSkuProps, {style: {display: ''}, html: this.offers[index].DISPLAY_PROPERTIES});
                }
            }
            if (!!this.obPrice)
            {
                strPrice = this.offers[index].PRICE.PRINT_DISCOUNT_VALUE;
                if (this.showOldPrice && (this.offers[index].PRICE.DISCOUNT_VALUE !== this.offers[index].PRICE.VALUE))
                {
                    strPrice += ' <span>'+this.offers[index].PRICE.PRINT_VALUE+'</span>';
                }
                BX.adjust(this.obPrice, {html: strPrice});
                if (this.showPercent)
                {
                    if (this.offers[index].PRICE.DISCOUNT_VALUE !== this.offers[index].PRICE.VALUE)
                    {
                        obData = {
                            style: {
                                display: ''
                            },
                            html: this.offers[index].PRICE.DISCOUNT_DIFF_PERCENT
                        };
                    }
                    else
                    {
                        obData = {
                            style: {
                                display: 'none'
                            },
                            html: ''
                        };
                    }
                    if (!!this.obDscPerc)
                    {
                        BX.adjust(this.obDscPerc, obData);
                    }
                    if (!!this.obSecondDscPerc)
                    {
                        BX.adjust(this.obSecondDscPerc, obData);
                    }
                }
            }
            this.offerNum = index;
            this.QuantitySet(this.offerNum);
        }
    };

    window.JCCatalogSectionViewed.prototype.InitBasketUrl = function()
    {
        switch (this.productType)
        {
            case 1://product
            case 2://set
                this.basketUrl = this.product.addUrl;
                break;
            case 3://sku
                this.basketUrl = this.offers[this.offerNum].ADD_URL;
                break;
        }
        this.basketParams = {
            'ajax_basket': 'Y'
        };
        if (this.showQuantity)
        {
            this.basketParams[this.basketData.quantity] = this.obQuantity.value;
        }
    };

    window.JCCatalogSectionViewed.prototype.FillBasketProps = function()
    {
        if (!this.visual.BASKET_PROP_DIV)
        {
            return;
        }
        var
            i = 0,
            propCollection = null,
            foundValues = false,
            obBasketProps = null;

        if (this.basketData.useProps && !this.basketData.emptyProps)
        {
            if (!!this.obPopupWin && !!this.obPopupWin.contentContainer)
            {
                obBasketProps = this.obPopupWin.contentContainer;
            }
        }
        else
        {
            obBasketProps = BX(this.visual.BASKET_PROP_DIV);
        }
        if (!obBasketProps)
        {
            return;
        }
        propCollection = obBasketProps.getElementsByTagName('select');
        if (!!propCollection && !!propCollection.length)
        {
            for (i = 0; i < propCollection.length; i++)
            {
                if (!propCollection[i].disabled)
                {
                    switch(propCollection[i].type.toLowerCase())
                    {
                        case 'select-one':
                            this.basketParams[propCollection[i].name] = propCollection[i].value;
                            foundValues = true;
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        propCollection = obBasketProps.getElementsByTagName('input');
        if (!!propCollection && !!propCollection.length)
        {
            for (i = 0; i < propCollection.length; i++)
            {
                if (!propCollection[i].disabled)
                {
                    switch(propCollection[i].type.toLowerCase())
                    {
                        case 'hidden':
                            this.basketParams[propCollection[i].name] = propCollection[i].value;
                            foundValues = true;
                            break;
                        case 'radio':
                            if (propCollection[i].checked)
                            {
                                this.basketParams[propCollection[i].name] = propCollection[i].value;
                                foundValues = true;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        if (!foundValues)
        {
            this.basketParams[this.basketData.props] = [];
            this.basketParams[this.basketData.props][0] = 0;
        }
    };

    window.JCCatalogSectionViewed.prototype.SendToBasket = function()
    {
        if (!this.canBuy)
        {
            return;
        }
        this.InitBasketUrl();
        this.FillBasketProps();
        this.basketParams[this.basketData.props] = [];
        this.basketParams[this.basketData.props]['RESERVE_REQ'] = this.product.reserveReq;
        BX.ajax.loadJSON(
            this.basketUrl,
            this.basketParams,
            BX.delegate(this.BasketResult, this),
            BX.delegate(this.BasketResult, this)
        );

    };

    window.JCCatalogSectionViewed.prototype.Basket = function()
    {
        var contentBasketProps = '';
        if (!this.canBuy)
        {
            return;
        }
        switch (this.productType)
        {
            case 1://product
            case 2://set
                if (this.basketData.useProps && !this.basketData.emptyProps)
                {
                    /*this.InitPopupWindow();
                    this.obPopupWin.setTitleBar({
                        content: BX.create('div', {
                            style: { marginRight: '30px', whiteSpace: 'nowrap' },
                            /!*text: BX.message('CVP_TITLE_BASKET_PROPS')*!/
                            text: BX.message('CVP_ADD_TO_BASKET_OK')

                        })
                    });
                    if (BX(this.visual.BASKET_PROP_DIV))
                    {
                        contentBasketProps = BX(this.visual.BASKET_PROP_DIV).innerHTML;
                    }
                    this.obPopupWin.setContent(contentBasketProps);
                    this.obPopupWin.setButtons([
                        new BasketButton({
                            ownerClass: this.obProduct.parentNode.parentNode.parentNode.className,
                            /!*text: BX.message('CVP_BTN_MESSAGE_SEND_PROPS'),*!/
                            text: BX.message('CVP_BTN_MESSAGE_BASKET_REDIRECT'),

                            events: {
                                click: BX.delegate(this.SendToBasket, this)
                            }
                        })
                    ]);
                    this.obPopupWin.show();*/
                    this.SendToBasket();
                }
                else
                {
                    this.SendToBasket();
                }
                break;
            case 3://sku
                this.SendToBasket();
                break;
        }
    };

    window.JCCatalogSectionViewed.prototype.BasketResult = function(arResult)
    {
        var strContent = '',
            strName = '',
            strPict = '',
            successful = true,
            buttons = [];

        if (!!this.obPopupWin)
        {
            this.obPopupWin.close();
        }
        if ('object' !== typeof arResult)
        {
            return false;
        }
        successful = ('OK' === arResult.STATUS);
        if (successful)
        {
            // Update basket in header.
            $.get("/include/basketinfo2.php?type=line", function(data){
                $('header .basket_personal a.basket').html(data);
            });
            // обновить кол-во в корзине для товара
            if (this.product.id) {
                setBasketCntForProducts(this.product.id);
            }
            BX.onCustomEvent('OnBasketChange');
            strName = this.product.name;
            switch(this.productType)
            {
                case 1://
                case 2://
                    strPict = this.product.pict.SRC;
                    break;
                case 3:
                    strPict = (!!this.offers[this.offerNum].PREVIEW_PICTURE ?
                            this.offers[this.offerNum].PREVIEW_PICTURE.SRC :
                            this.defaultPict.pict.SRC
                    );
                    break;
            }
            strContent = '<div style="width: 96%; margin: 10px 2%; text-align: center;"><p>'+strName+'</p></div>';
            buttons = [
                new BasketButton({
                    ownerClass: this.obProduct.parentNode.parentNode.parentNode.className,
                    text: BX.message("CVP_BTN_MESSAGE_BASKET_REDIRECT"),
                    events: {
                        click: BX.delegate(function(){
                            location.href = (!!this.basketData.basketUrl ? this.basketData.basketUrl : BX.message('CVP_BASKET_URL'));
                        }, this)
                    }
                })
            ];
        }
        else
        {
            strContent = (!!arResult.MESSAGE ? arResult.MESSAGE : BX.message('CVP_BASKET_UNKNOWN_ERROR'));
            buttons = [
                new BasketButton({
                    ownerClass: this.obProduct.parentNode.parentNode.parentNode.className,
                    text: BX.message('CVP_BTN_MESSAGE_CLOSE'),
                    events: {
                        click: BX.delegate(this.obPopupWin.close, this.obPopupWin)
                    }
                })
            ];
        }
        /*this.InitPopupWindow();
        this.obPopupWin.setTitleBar({
            content: BX.create('div', {
                style: { marginRight: '30px', whiteSpace: 'nowrap' },
                text: (successful ? BX.message('CVP_TITLE_SUCCESSFUL') : BX.message('CVP_TITLE_ERROR'))
            })
        });
        this.obPopupWin.setContent(strContent);
        this.obPopupWin.setButtons(buttons);
        this.obPopupWin.show();*/
    };

    window.JCCatalogSectionViewed.prototype.InitPopupWindow = function()
    {
        /*if (!!this.obPopupWin)
        {
            return;
        }
        this.obPopupWin = BX.PopupWindowManager.create('CatalogSectionBasket_'+this.visual.ID, null, {
            autoHide: true,
            offsetLeft: 0,
            offsetTop: 0,
            overlay : true,
            closeByEsc: true,
            titleBar: true,
            closeIcon: {top: '15px', right: '15px'}
        });*/
    };

    /* Custom jquery functions*/

    $(document).on('click','.kd-collapse-btn',function (e) {
        e.preventDefault();

        var collapseToggles = $(this).parents('.kd-lc-wrapper').find('#product_table .kd-show_block-but'),
            collapseBtn = $(this),
            collapseText = $(this).find('.kd-collapse-text');


        collapseBtn.toggleClass('collapsed');

        if(collapseBtn.hasClass('collapsed')) {
            collapseToggles.each(function () {
                var prodId = $(this).parents('tr').data('product_id'),
                    descrBlock = $('#'+prodId+'_desc');
                if(!descrBlock.hasClass('kd-product-detail-block-show')) {
                    descrBlock.addClass('kd-product-detail-block-show');
                    $(this).addClass('kd-desc-show-but-down');
                }
            });
            collapseText.text('Свернуть все')
        } else {
            collapseToggles.each(function () {
                var prodId = $(this).parents('tr').data('product_id'),
                    descrBlock = $('#'+prodId+'_desc');
                if(descrBlock.hasClass('kd-product-detail-block-show')) {
                    descrBlock.removeClass('kd-product-detail-block-show');
                    $(this).removeClass('kd-desc-show-but-down');
                }
            });
            collapseText.text('Развернуть все')
        }


    });
    $(document).on('click', '.kd-show-title-btn',function (e) {
        e.preventDefault();
        var text = $(this).find('.kd-collapse-text');

        if($(this).hasClass('full-text')) {
            text.html('Названия полностью');
            $(this).removeClass('full-text');
            $('.kd-last_viewed_items').removeClass('show-title-full');
            on_resize_textbtn();
        } else {
            text.html('Названия в одну строку');
            $(this).addClass('full-text');
            $('.kd-last_viewed_items').addClass('show-title-full');
        }
    });
})(window);

$(function(){
    on_resize_textbtn();
    mobile_textbtn();
    $(window).resize(function() {
        var $this = $(this);
        var delay = 300;
        clearTimeout($this.data('timer_resize'));
        $this.data('timer_resize', setTimeout(function(){
            $this.removeData('timer_resize');
            on_resize_textbtn();
            mobile_textbtn();
        }, delay));
    });


    $(document).on("click",".kd-lvi-td-to_top-image, .kd-lvi-td-to_top-text",function(){
        var id=$(this).closest("tr[data-tp_id]").attr("data-tp_id");
        var pr=$(this).closest(".kd-lvi-td-to_top");

        const confirmText = "Товар будет удален из избранного. Вы уверены, что хотите удалить?";
        if (location.pathname === "/personal/favorites/product/" && pr.hasClass('kd-lvi-td-to_top-active')) {
            if (!confirm(confirmText)) {
                return;
            }
        }

        $.ajax({
            type: "POST",
            url: "/ajax/favorite.php",
            data: ({"id":id}),
            success: function(data){
                switch(data.trim()){
                    case 'done' :
                        pr.addClass("kd-lvi-td-to_top-active");
                        pr.children('.kd-lvi-td-to_top-image-wrap').attr('title',  BX.message('O2K_IN_FAVORITE'));
                        break;
                    case 'deleted' :
                        pr.removeClass("kd-lvi-td-to_top-active");
                        pr.children('.kd-lvi-td-to_top-image-wrap').attr('title',  BX.message('O2K_OUT_FAVORITE'));
                        break;
                    case 'fail' :
                        alert("error");
                        break;
                }
            }
        })
    });
    $('.item_slider').each(function(i, el){
        var slider = $(el),
            images = slider.children('.item_images'),
            thumbs = slider.children('.item_thumbs'),
            imagesList = images.children('ul'),
            thumbsList = thumbs.children('ul'),
            btnUp   = slider.find('.item_thumbs_slide_up'),
            btnDown = slider.find('.item_thumbs_slide_down'),

            iThumbsListViewHeight = thumbsList.height(),
            iThumbsItemsCount = thumbsList.children('li').length,
            iThumbsItemHeight = thumbsList.children('li').eq(0).outerHeight(true), // height + border + margin (true)
            // iThumbsItemMargin = 30, // margin-bottom set in css
            // iThumbsItemTotalHeight = iThumbsItemHeight + iThumbsItemMargin,
            iThumbsListTotalHeight = iThumbsItemHeight * iThumbsItemsCount;

        $.each([btnUp, btnDown], function(j, btn){
            btn.on('click', function(){
                if (btn.hasClass('disabled')){
                    return false;
                }

                var $this = $(this),
                    iScrolled = thumbsList.scrollTop(),
                    iScrollTo = 0;

                if ($this.hasClass('item_thumbs_slide_up')){
                    iScrollTo = -iThumbsItemHeight;
                } else {
                    iScrollTo = iThumbsItemHeight;
                }

                thumbsList.scrollTop(iScrolled + iScrollTo);
                iScrolled = thumbsList.scrollTop();

                btnUp.toggleClass('disabled', (iScrolled < iThumbsItemHeight));
                btnDown.toggleClass('disabled', ((iThumbsListTotalHeight - iThumbsListViewHeight - iScrolled) < iThumbsItemHeight));
            });
        })

        thumbs.on('click', '.item_thumb', function(e){
            var $this = $(this);
            if (!$this.hasClass('active')){
                var idx = $this.parent().children().removeClass('active').index($this);
                $this.addClass('active');
                images.find('.item_image').removeClass('active').eq(idx).addClass('active');
            }
            return false;
        });
    });

    if ($('#viewedProducts').length && !$('.newstextul').length && !$('#searchResult').length && $('.megawrap-col_main').length && !$('#saved_basket').length) {
        $('#viewedProducts').addClass('viewedProducts_catalog');
    }

    $(document).on("click", ".design_toggler", function() {
        if ($(this).text() == BX.message('BACK_TO_OLD_DESIGN')) {
            $(this).text(BX.message('BACK_TO_NEW_DESIGN'));
            setCookie('old_filter', 'Y', {expires: 0, 'path': '/'});
        } else {
            $(this).text(BX.message('BACK_TO_OLD_DESIGN'));
            setCookie('old_filter', '0', {'max-age': -1, 'path': '/'});
        }
        window.location.reload();
    });
});
$(document).ready(function() {
    const $resetButton = $('.quick_search_reset');
    const $quickSearchInput = $('input[name="quick_search"]');
    const $quickSearchForm = $('.quick_search');
    function quickSearch() {
        let searchText = $quickSearchInput.val().trim();
        let url = location.pathname;
        if (searchText.length > 0) {
            if (url.match(/\?/)) {
                url = url + '&qs=' + searchText;
            } else {
                url = url + '?qs=' + searchText;
            }
        }
        location.href = url;
    }
    if ($quickSearchInput.length > 0) {
        if ($quickSearchInput.val().length > 0 && document.documentElement.clientWidth < 600) {
            $('html, body').animate({
                scrollTop: $quickSearchForm.offset().top
            }, 100);
        }
        if ($quickSearchInput.val().length > 0) {
            $resetButton.css('display', 'block');
        }
        $quickSearchInput.on('input', function () {
            if ($(this).val().length > 0) {
                $resetButton.css('display', 'block');
            } else {
                $resetButton.css('display', 'none');
            }
        });
        $quickSearchForm.on('submit', function (e) {
            e.preventDefault();
            quickSearch();
        });
        $resetButton.on('mouseup', function (e) {
            e.preventDefault();
            $quickSearchInput.val('');
            $quickSearchForm.trigger('submit');
        });
    }
    window.highlightingSearch = function () {
        const $quickSearchInput = $('input[name="quick_search"]');
        if ($quickSearchInput.length > 0) {
            const searchText = $quickSearchInput.val().trim().toLowerCase();
            if (searchText.length > 0) {
                const html = $(this).html();
                if (html.indexOf('search_highlight') === -1) {
                    const start = html.toLowerCase().indexOf(searchText);
                    if (start !== -1) {
                        const end = start + searchText.length;
                        let highlightHtml = html.slice(0, start);
                        highlightHtml += '<span class="search_highlight">';
                        highlightHtml += html.slice(start, end);
                        highlightHtml += '</span>';
                        highlightHtml += html.slice(end);
                        $(this).html(highlightHtml);
                    }
                }
            }
        }
    }
    $('.name_div a').each(window.highlightingSearch);
    $('.insidetable').each(window.highlightingSearch);
    $('.seesynonym-wrap .kd-dashed').each(window.highlightingSearch);
    $('.seesynonym-wrap .kd-block-name-seesynonym').each(window.highlightingSearch);
});
$(function(){
    const $galeyTopBlock = $('.galery-top');
    const $galleryBlock = $('.custom-galery');
    const $galleryBlockOnlyPhoto = $('.custom-galery_only-photo');
    if ($galeyTopBlock.length && $galleryBlock.length) {
        $galeyTopBlock.append($galleryBlock);
    } else if ($galeyTopBlock.length && $galleryBlockOnlyPhoto.length) {
        $galeyTopBlock.append($galleryBlockOnlyPhoto);
    }
});
$(function () {
    $(document).on('click', '.sort_btn', function (e) {
        e.preventDefault();
        $(this).siblings('.sort_btn').removeClass('current')
        $(this).addClass('current');

        var display = $(this).data('display');
        $.ajax({
            url: '/ajax/display_mode.php',
            type: 'post',
            dataType: 'text',
            data: {'display':display},
            success: function(res){}
        });

        $('.favorites-videos').removeClass('block list').addClass(display);
        $('.favorites-catalogs').removeClass('block list').addClass(display);

        $('.sort_display .sort_btn').removeClass('current');
        $('.sort_display a[data-display='+display+']').addClass('current');

    });

    // Валидация галочки согласия
    $('.js-check-agree input').change(function () {
        var self = $(this);

        if (!self.is(":checked")) {
            self.parents('.kd-form__group_checkbox').addClass('kd-form__group-error');
        } else {
            self.parents('.kd-form__group_checkbox').removeClass('kd-form__group-error');
        }
    });

    $(document).on('click', '#cena-zapros_form input[type=submit]', function (e) {
        var form = $(this).closest('form'),
            checkbox = form.find('#user-checkbox');
        if (checkbox.length && !checkbox.prop('checked')) {
            checkbox.closest('.js-check-agree').addClass('kd-form__group-error');
            return false;
        } else {
            form.submit();
        }
    });

    $(document).on('change', 'select.js-select-offer', function (e) {
        var offerId = $(this).val();
        var container = $(this).closest('.js-product-row');
        var productId = container.attr('data-product');
        var productOffers = container.nextUntil('.js-product-row').filter('[data-product_id='+productId+']');
        productOffers.each(function(elem){
            if($(this).attr('data-tp_id') == offerId) {
                $(this).css('display', 'flex');
            } else {
                $(this).hide();
            }
        });
        var articul = $('[data-tp_id='+offerId+'] .kd-lvi-td-atricle-wrap').html();
        container.find('.js-cell-catnumber').html(articul);
    });

    $(document).on('touchstart', '.bx-touch .kd-help-block.labels', function (){
        let elRight = $(this).position().left + $(this).width();
        let rightMargin = $(window).width() - elRight;
        if (rightMargin < 200) {
            $(this).find('.kd-help-block-text').css('right', 200 - rightMargin + 30 + 'px');
        }
    });
});

/* End */
;; /* /local/templates/diam/components/bitrix/news/video_new/bitrix/news.detail/.default/script.js?17271593953081*/
; /* /embed/player/scripts/script.js?172715938411200*/
; /* /local/templates/diam/components/bitrix/catalog.section/new_cat/script.js?172715939560985*/
