// source --> https://ustroistvo-avtomobilya.ru/wp-content/plugins/dw-question-answer-pro/templates/assets/js/dwqa-user-profile.js?ver=190820170952 
jQuery(function($){
	function updateCoords(coords){
		$('#crop-h').val(coords.h);
		$('#crop-w').val(coords.w);
		$('#crop-x').val(coords.x);
		$('#crop-x2').val(coords.x2);
		$('#crop-y').val(coords.y);
		$('#crop-y2').val(coords.y2);
        // console.log(coords);
    }
    function showPreview(coords) {
		if ( parseInt(coords.w) > 0 ) {
			var fw = 150;
			var fh = 150;
			var rx = fw / coords.w;
			var ry = fh / coords.h;
			// console.log(ry * image.naturalHeight);
			// console.log(ry * coords.y);
			$('#avatar-crop').find('img').each(function(){
				var w = $('#popup-crop .jcrop-holder').width();
				var h = $('#popup-crop .jcrop-holder').height();
				$(this).css({
					width: Math.round(rx * w) + 'px',
					height: Math.round(ry * h) + 'px',
					marginLeft: '-' + Math.round(rx * coords.x) + 'px',
					marginTop: '-' + Math.round(ry * coords.y) + 'px'
				});
			});
		}
	}

	$('#dwqa-upload-user-avatar').on('change', function(){
		var file = this.files[0];
		if(file == 'undefined'){
			return false;
		}

		var formData = new FormData();
		formData.append('action', 'dwqa_upload_avatar');
		formData.append('nonce', dwqa_profile.ajax_nonce);
		formData.append('file', file);

		$.ajax({
			url: dwqa_profile.ajax_url,
			type: "POST",
			data: formData,
			success: function (data) {
				console.log(data);
				if(data.success){
					$('#attachment_file').val(data.data.upload.file);
					var html = '<img src="'+data.data.upload.url+'">';
					$('#popup-crop').html(html);
					$('#avatar-crop').html(html);

					$('#popup-crop').find('img').Jcrop({
				        /*setSelect: [400, 200, 50, 50], */
				        aspectRatio: 1,
				        onSelect: showPreview, 
				        onChange: updateCoords
				    }/*, function(){
				        jcrop_api = this;
				    }*/);
				    $('.dwqa-poup').show();
				    
				}else{
					alert(data.data);
				}
				// alert(msg)
			},
			cache: false,
			contentType: false,
			processData: false
		});

		// e.preventDefault();
	});

	$('#button-crop').on('click', function(){
		$('.dwqa-poup').hide();
		var attachment_file = $('#attachment_file').val();
		var h = $('#crop-h').val();
		var w = $('#crop-w').val();
		var x = $('#crop-x').val();
		var x2 = $('#crop-x2').val();
		var y = $('#crop-y').val();
		var y2 = $('#crop-y2').val();

		var ui_w = $('#popup-crop .jcrop-holder').width();
		var ui_h = $('#popup-crop .jcrop-holder').height();

		$.ajax({
			url: dwqa_profile.ajax_url,
			type: "POST",
			dataType: 'json',
			data: {
				action: 'dwqa_crop_avatar',
				nonce: dwqa_profile.ajax_nonce,
				attachment_file: attachment_file,
				h: h,
				w: w,
				x: x,
				x2: x2,
				y: y,
				y2: y2,
				ui_w: ui_w,
				ui_h: ui_h
			},
			success: function (data) {
				console.log(data);
				if(data.success){
					var html = '<img src="'+data.data.cropped.url+'">';
					$('#dwqa-user-avatar').html(html);
				}else{
					alert(data.data);
				}
				// alert(msg)
			}
		});

	});


	$('#dwqa-upload-user-cover-image').on('change', function(){
		var file = this.files[0];
		if(file == 'undefined'){
			return false;
		}

		var formData = new FormData();
		formData.append('action', 'dwqa_upload_cover_image');
		formData.append('nonce', dwqa_profile.ajax_nonce);
		formData.append('file', file);

		$.ajax({
			url: dwqa_profile.ajax_url,
			type: "POST",
			data: formData,
			success: function (data) {
				console.log(data);
				if(data.success){
					// $('#attachment_file').val(data.data.upload.file);
					var html = '<img src="'+data.data.upload.url+'">';
					$('#dwqa-user-cover-image').html(html);
				}else{
					alert(data.data);
				}
				// alert(msg)
			},
			cache: false,
			contentType: false,
			processData: false
		});

		// e.preventDefault();
	});
});
// source --> https://ustroistvo-avtomobilya.ru/wp-content/plugins/fitvids-for-wordpress/jquery.fitvids.js?ver=1.1 
/*jshint browser:true */
/*!
 * FitVids 1.1
 *
 * Copyright 2013, Chris Coyier - http://css-tricks.com + Dave Rupert - http://daverupert.com
 * Credit to Thierry Koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/
 * Released under the WTFPL license - http://sam.zoy.org/wtfpl/
 *
 */

;(function( $ ){

    'use strict';

    $.fn.fitVids = function( options ) {
        var settings = {
            customSelector: null,
            ignore: null
        };

        if(!document.getElementById('fit-vids-style')) {
            // appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js
            var head = document.head || document.getElementsByTagName('head')[0];
            var css = '.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}';
            var div = document.createElement("div");
            div.innerHTML = '<p>x</p><style id="fit-vids-style">' + css + '</style>';
            head.appendChild(div.childNodes[1]);
        }

        if ( options ) {
            $.extend( settings, options );
        }

        return this.each(function(){
            var selectors = [
                'iframe[src*="player.vimeo.com"]',
                'iframe[src*="youtube.com"]',
                'iframe[src*="youtu.be"]',
                'iframe[src*="youtube-nocookie.com"]',
                'iframe[src*="kickstarter.com"][src*="video.html"]',
                'iframe[src*="facebook.com"]',
                'object',
                'embed'
            ];

            if (settings.customSelector) {
                selectors.push(settings.customSelector);
            }

            var ignoreList = '.fitvidsignore';

            if(settings.ignore) {
                ignoreList = ignoreList + ', ' + settings.ignore;
            }

            var $allVideos = $(this).find(selectors.join(','));
            $allVideos = $allVideos.not('object object'); // SwfObj conflict patch
            $allVideos = $allVideos.not(ignoreList); // Disable FitVids on this video.

            $allVideos.each(function(){
                var $this = $(this);
                if($this.parents(ignoreList).length > 0) {
                    return; // Disable FitVids on this video.
                }
                if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; }
                if ((!$this.css('height') && !$this.css('width')) && (isNaN($this.attr('height')) || isNaN($this.attr('width'))))
                {
                    $this.attr('height', 9);
                    $this.attr('width', 16);
                }
                var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(),
                    width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(),
                    aspectRatio = height / width;
                if(!$this.attr('name')){
                    var videoName = 'fitvid' + $.fn.fitVids._count;
                    $this.attr('name', videoName);
                    $.fn.fitVids._count++;
                }
                $this.wrap('<div class="fluid-width-video-wrapper"></div>').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+'%');
                $this.removeAttr('height').removeAttr('width');
            });
        });
    };

    // Internal counter for unique video names.
    $.fn.fitVids._count = 0;

// Works with either jQuery or Zepto
})( window.jQuery || window.Zepto );
// source --> https://ustroistvo-avtomobilya.ru/wp-content/plugins/table-of-contents-plus/front.min.js?ver=2411.1 
!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):t("object"==typeof module&&module.exports?require("jquery"):jQuery)}(function(t){function e(t){return t.replace(/(:|\.|\/)/g,"\\$1")}var o="1.6.0",i={},l={exclude:[],excludeWithin:[],offset:0,direction:"top",delegateSelector:null,scrollElement:null,scrollTarget:null,beforeScroll:function(){},afterScroll:function(){},easing:"swing",speed:400,autoCoefficient:2,preventDefault:!0},s=function(e){var o=[],i=!1,l=e.dir&&"left"===e.dir?"scrollLeft":"scrollTop";return this.each(function(){var e=t(this);return this!==document&&this!==window?!document.scrollingElement||this!==document.documentElement&&this!==document.body?void(e[l]()>0?o.push(this):(e[l](1),i=e[l]()>0,i&&o.push(this),e[l](0))):(o.push(document.scrollingElement),!1):void 0}),o.length||this.each(function(){"BODY"===this.nodeName&&(o=[this])}),"first"===e.el&&o.length>1&&(o=[o[0]]),o};t.fn.extend({scrollable:function(t){var e=s.call(this,{dir:t});return this.pushStack(e)},firstScrollable:function(t){var e=s.call(this,{el:"first",dir:t});return this.pushStack(e)},smoothScroll:function(o,i){if(o=o||{},"options"===o)return i?this.each(function(){var e=t(this),o=t.extend(e.data("ssOpts")||{},i);t(this).data("ssOpts",o)}):this.first().data("ssOpts");var l=t.extend({},t.fn.smoothScroll.defaults,o),s=function(o){var i=this,s=t(this),n=t.extend({},l,s.data("ssOpts")||{}),c=l.exclude,a=n.excludeWithin,r=0,h=0,u=!0,d={},p=t.smoothScroll.filterPath(location.pathname),f=t.smoothScroll.filterPath(i.pathname),m=location.hostname===i.hostname||!i.hostname,g=n.scrollTarget||f===p,v=e(i.hash);if(n.scrollTarget||m&&g&&v){for(;u&&r<c.length;)s.is(e(c[r++]))&&(u=!1);for(;u&&h<a.length;)s.closest(a[h++]).length&&(u=!1)}else u=!1;u&&(n.preventDefault&&o.preventDefault(),t.extend(d,n,{scrollTarget:n.scrollTarget||v,link:i}),t.smoothScroll(d))};return null!==o.delegateSelector?this.undelegate(o.delegateSelector,"click.smoothscroll").delegate(o.delegateSelector,"click.smoothscroll",s):this.unbind("click.smoothscroll").bind("click.smoothscroll",s),this}}),t.smoothScroll=function(e,o){if("options"===e&&"object"==typeof o)return t.extend(i,o);var l,s,n,c,a,r=0,h="offset",u="scrollTop",d={},p={};"number"==typeof e?(l=t.extend({link:null},t.fn.smoothScroll.defaults,i),n=e):(l=t.extend({link:null},t.fn.smoothScroll.defaults,e||{},i),l.scrollElement&&(h="position","static"===l.scrollElement.css("position")&&l.scrollElement.css("position","relative"))),u="left"===l.direction?"scrollLeft":u,l.scrollElement?(s=l.scrollElement,/^(?:HTML|BODY)$/.test(s[0].nodeName)||(r=s[u]())):s=t("html, body").firstScrollable(l.direction),l.beforeScroll.call(s,l),n="number"==typeof e?e:o||t(l.scrollTarget)[h]()&&t(l.scrollTarget)[h]()[l.direction]||0,d[u]=n+r+l.offset,c=l.speed,"auto"===c&&(a=Math.abs(d[u]-s[u]()),c=a/l.autoCoefficient),p={duration:c,easing:l.easing,complete:function(){l.afterScroll.call(l.link,l)}},l.step&&(p.step=l.step),s.length?s.stop().animate(d,p):l.afterScroll.call(l.link,l)},t.smoothScroll.version=o,t.smoothScroll.filterPath=function(t){return t=t||"",t.replace(/^\//,"").replace(/(?:index|default).[a-zA-Z]{3,4}$/,"").replace(/\/$/,"")},t.fn.smoothScroll.defaults=l}),jQuery.cookie=function(t,e,o){if(arguments.length>1&&"[object Object]"!==String(e)){if(o=jQuery.extend({},o),(null===e||void 0===e)&&(o.expires=-1),"number"==typeof o.expires){var i=o.expires,l=o.expires=new Date;l.setDate(l.getDate()+i)}return e=String(e),document.cookie=[encodeURIComponent(t),"=",o.raw?e:encodeURIComponent(e),o.expires?"; expires="+o.expires.toUTCString():"",o.path?"; path="+o.path:"",o.domain?"; domain="+o.domain:"",o.secure?"; secure":""].join("")}o=e||{};var s,n=o.raw?function(t){return t}:decodeURIComponent;return(s=new RegExp("(?:^|; )"+encodeURIComponent(t)+"=([^;]*)").exec(document.cookie))?n(s[1]):null},jQuery(document).ready(function(t){if("undefined"!=typeof tocplus){if(t.fn.shrinkTOCWidth=function(){t(this).css({width:"auto",display:"table"}),/MSIE 7\./.test(navigator.userAgent)&&t(this).css("width","")},1==tocplus.smooth_scroll){var e=hostname=pathname=qs=hash=null;t("body a").click(function(){if(hostname=t(this).prop("hostname"),pathname=t(this).prop("pathname"),qs=t(this).prop("search"),hash=t(this).prop("hash"),pathname.length>0&&"/"!=pathname.charAt(0)&&(pathname="/"+pathname),window.location.hostname==hostname&&window.location.pathname==pathname&&window.location.search==qs&&""!==hash){var o=hash.replace(/([ !"$%&'()*+,.\/:;<=>?@[\]^`{|}~])/g,"\\$1");t(o).length>0?e=hash:(anchor=hash,anchor=anchor.replace("#",""),e='a[name="'+anchor+'"]',0==t(e).length&&(e="")),offset="undefined"!=typeof tocplus.smooth_scroll_offset?-1*tocplus.smooth_scroll_offset:t("#wpadminbar").length>0&&t("#wpadminbar").is(":visible")?-30:0,e&&t.smoothScroll({scrollTarget:e,offset:offset})}})}if("undefined"!=typeof tocplus.visibility_show){var o="undefined"!=typeof tocplus.visibility_hide_by_default?!0:!1;if(t.cookie)var i=t.cookie("tocplus_hidetoc")?tocplus.visibility_show:tocplus.visibility_hide;else var i=tocplus.visibility_hide;o&&(i=i==tocplus.visibility_hide?tocplus.visibility_show:tocplus.visibility_hide),t("#toc_container p.toc_title").append(' <span class="toc_toggle"><span class="toc_brackets">[</span><a href="#">'+i+'</a><span class="toc_brackets">]</span></span>'),i==tocplus.visibility_show&&(t("ul.toc_list").hide(),t("#toc_container").addClass("contracted").shrinkTOCWidth()),t("span.toc_toggle a").click(function(e){switch(e.preventDefault(),t(this).html()){case t("<div/>").html(tocplus.visibility_hide).text():t(this).html(tocplus.visibility_show),t.cookie&&(o?t.cookie("tocplus_hidetoc",null,{path:"/"}):t.cookie("tocplus_hidetoc","1",{expires:30,path:"/"})),t("ul.toc_list").hide("fast"),t("#toc_container").addClass("contracted").shrinkTOCWidth();break;case t("<div/>").html(tocplus.visibility_show).text():default:t(this).html(tocplus.visibility_hide),t.cookie&&(o?t.cookie("tocplus_hidetoc","1",{expires:30,path:"/"}):t.cookie("tocplus_hidetoc",null,{path:"/"})),t("#toc_container").css("width",tocplus.width).removeClass("contracted"),t("ul.toc_list").show("fast")}})}}});