$(document).ready(function(){

    var i = true;

    $('.i-expand__data').each(function(){
        $(this).closest('.i-expand').data("rel", $(this));
    });

    $('.i-expand__tick').click(function(){


         $(document).unbind("click");

         var expand = $(this).closest('.i-expand');

         expand.data("rel").show();
         $(expand).addClass('i-expand_on');

         $(document).click(function(){


               if (i) {

                   expand.data("rel").show();
                   $(expand).addClass('i-expand_on');

                   i = false;

               } else {

                   expand.data("rel").hide();
                   $(expand).removeClass('i-expand_on');

                   i = true;
                   $(this).unbind("click");
               }


         });



    });


});

$(document).ready(function(){

$('.m-check tr:nth-child(even)').addClass('i-check_bg');

   var index = $('.m-slides__item_on').index('.m-slides__item');

   function removeDisabled() {
       $('.m-pic_arrow').removeClass('m-pic_arrow_disabled_l').removeClass('m-pic_arrow_disabled_r');
   }

   function indCount() {
       if (index == 0) {
           $('.m-pic_arrow_l').addClass('m-pic_arrow_disabled_l');
       }
       else if (index == $('.m-slides__item').length - 1) {
           $('.m-pic_arrow_r').addClass('m-pic_arrow_disabled_r');
       }
   }

   indCount();

   $('.m-pic_arrow_r').click(function(){

        if (index < $('.m-slides__item').length - 1) {
            $('.m-slides__description').hide();

            $('.m-slides__item').hide().removeClass('m-slides__item_on');
            $($('.m-slides__item')[index += 1]).fadeIn(200).addClass('m-slides__item_on');

            $('.m-slides__item_on .m-slides__description').show();
            $('.m-slides__description').hide();
            $('.m-slides__description').fadeIn(400);

            removeDisabled();
            indCount();
        }

   });

   $('.m-pic_arrow_l').click(function(){

        if (index >= 1) {
            $('.m-slides__description').hide();

            $('.m-slides__item').hide().removeClass('m-slides__item_on');
            $($('.m-slides__item')[index -= 1]).fadeIn(200).addClass('m-slides__item_on');


            $('.m-slides__item_on .m-slides__description').show();
            $('.m-slides__description').hide();
            $('.m-slides__description').fadeIn(400);

            removeDisabled();
            indCount();
        }

   });

});

$(document).ready(function(){
	$('#search_text').jsonSuggest({url: cmfBaseUrl+'/mainAjax/search/suggest.php', minCharacters: 2, maxResults: 6});
});

sizearr = false;
$(document).ready(function(){
	if (!sizearr) return;
	
	detach = function(select){
		$('option','#'+select).each(function(){
			el = $(this).detach();
			$('#'+select).data(el.val(),el);
			$('#'+select).append($('#'+select).data('-1')).val('-1');
		});
	}
	detach('size_select');
	detach('color_select');

	var f = false; i = 0;
	for(size in sizearr) {
		++i; if (size == '-2') f = true;
		$('#size_select').append($('#size_select').data(size));
	}
	
	if (f && i == 1) {
		$('#product_size_block').remove();
		for(color in sizearr[-2]) {
			$('#color_select').append($('#color_select').data(sizearr[-2][color]));
		}
	}
	
	$('#size_select').change(function(){
		$('option:first','#color_select').text('Укажите цвет');
		detach('color_select');
		for(color in sizearr[$(this).val()]) {
			$('#color_select').append($('#color_select').data(sizearr[$(this).val()][color]));
		}
	});
	
	
});

$(document).ready(function(){
	$('#order_item_price').each(function(){
		$(this).data('price', $(this).text());
	})
	
	if (typeof(delivery) == 'undefined' || delivery.length == 0) return;
	
	$('#basketOrder1_delivery').change(function(){
		$('#order_item_price').text($('#order_item_price').data('price')*1 + delivery[$(this).val()]*1);
		$('#delivery_item','#order_items').remove();
		$('#order_items').append('<li id="delivery_item">'+$('option:selected',this).text()+'</li>');
	});
	
	$('#basketOrder1_delivery').trigger('change');
});

$(document).ready(function(){
	$('.form_voting li a').each(function(index){
		$(this).click(function(){
			$('#opinion_score').val(index+1);
			return false;
		});
	});
});

// ColorBox v1.3.17.2 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+

(function(a,b,c){function bc(b){if(!U){P=b,_(),y=a(P),Q=0,K.rel!=="nofollow"&&(y=a("."+g).filter(function(){var b=a.data(this,e).rel||this.rel;return b===K.rel}),Q=y.index(P),Q===-1&&(y=y.add(P),Q=y.length-1));if(!S){S=T=!0,r.show();if(K.returnFocus)try{P.blur(),a(P).one(l,function(){try{this.focus()}catch(a){}})}catch(c){}q.css({opacity:+K.opacity,cursor:K.overlayClose?"pointer":"auto"}).show(),K.w=Z(K.initialWidth,"x"),K.h=Z(K.initialHeight,"y"),X.position(),o&&z.bind("resize."+p+" scroll."+p,function(){q.css({width:z.width(),height:z.height(),top:z.scrollTop(),left:z.scrollLeft()})}).trigger("resize."+p),ba(h,K.onOpen),J.add(D).hide(),I.html(K.close).show()}X.load(!0)}}function bb(){var a,b=f+"Slideshow_",c="click."+f,d,e,g;K.slideshow&&y[1]?(d=function(){F.text(K.slideshowStop).unbind(c).bind(j,function(){if(Q<y.length-1||K.loop)a=setTimeout(X.next,K.slideshowSpeed)}).bind(i,function(){clearTimeout(a)}).one(c+" "+k,e),r.removeClass(b+"off").addClass(b+"on"),a=setTimeout(X.next,K.slideshowSpeed)},e=function(){clearTimeout(a),F.text(K.slideshowStart).unbind([j,i,k,c].join(" ")).one(c,d),r.removeClass(b+"on").addClass(b+"off")},K.slideshowAuto?d():e()):r.removeClass(b+"off "+b+"on")}function ba(b,c){c&&c.call(P),a.event.trigger(b)}function _(b){K=a.extend({},a.data(P,e));for(b in K)a.isFunction(K[b])&&b.substring(0,2)!=="on"&&(K[b]=K[b].call(P));K.rel=K.rel||P.rel||"nofollow",K.href=K.href||a(P).attr("href"),K.title=K.title||P.title,typeof K.href=="string"&&(K.href=a.trim(K.href))}function $(a){return K.photo||/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(a)}function Z(a,b){return Math.round((/%/.test(a)?(b==="x"?z.width():z.height())/100:1)*parseInt(a,10))}function Y(c,d,e){e=b.createElement("div"),c&&(e.id=f+c),e.style.cssText=d||"";return a(e)}var d={transition:"elastic",speed:300,width:!1,initialWidth:"600",innerWidth:!1,maxWidth:!1,height:!1,initialHeight:"450",innerHeight:!1,maxHeight:!1,scalePhotos:!0,scrolling:!0,inline:!1,html:!1,iframe:!1,fastIframe:!0,photo:!1,href:!1,title:!1,rel:!1,opacity:.9,preloading:!0,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:!1,returnFocus:!0,loop:!0,slideshow:!1,slideshowAuto:!0,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:!1,onLoad:!1,onComplete:!1,onCleanup:!1,onClosed:!1,overlayClose:!0,escKey:!0,arrowKey:!0,top:!1,bottom:!1,left:!1,right:!1,fixed:!1,data:!1},e="colorbox",f="cbox",g=f+"Element",h=f+"_open",i=f+"_load",j=f+"_complete",k=f+"_cleanup",l=f+"_closed",m=f+"_purge",n=a.browser.msie&&!a.support.opacity,o=n&&a.browser.version<7,p=f+"_IE6",q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X;X=a.fn[e]=a[e]=function(b,c){var f=this;b=b||{};if(!f[0]){if(f.selector)return f;f=a("<a/>"),b.open=!0}c&&(b.onComplete=c),f.each(function(){a.data(this,e,a.extend({},a.data(this,e)||d,b)),a(this).addClass(g)}),(a.isFunction(b.open)&&b.open.call(f)||b.open)&&bc(f[0]);return f},X.init=function(){z=a(c),r=Y().attr({id:e,"class":n?f+(o?"IE6":"IE"):""}),q=Y("Overlay",o?"position:absolute":"").hide(),s=Y("Wrapper"),t=Y("Content").append(A=Y("LoadedContent","width:0; height:0; overflow:hidden"),C=Y("LoadingOverlay").add(Y("LoadingGraphic")),D=Y("Title"),E=Y("Current"),G=Y("Next"),H=Y("Previous"),F=Y("Slideshow").bind(h,bb),I=Y("Close")),s.append(Y().append(Y("TopLeft"),u=Y("TopCenter"),Y("TopRight")),Y(!1,"clear:left").append(v=Y("MiddleLeft"),t,w=Y("MiddleRight")),Y(!1,"clear:left").append(Y("BottomLeft"),x=Y("BottomCenter"),Y("BottomRight"))).children().children().css({"float":"left"}),B=Y(!1,"position:absolute; width:9999px; visibility:hidden; display:none"),a("body").prepend(q,r.append(s,B)),t.children().hover(function(){a(this).addClass("hover")},function(){a(this).removeClass("hover")}).addClass("hover"),L=u.height()+x.height()+t.outerHeight(!0)-t.height(),M=v.width()+w.width()+t.outerWidth(!0)-t.width(),N=A.outerHeight(!0),O=A.outerWidth(!0),r.css({"padding-bottom":L,"padding-right":M}).hide(),G.click(function(){X.next()}),H.click(function(){X.prev()}),I.click(function(){X.close()}),J=G.add(H).add(E).add(F),t.children().removeClass("hover"),q.click(function(){K.overlayClose&&X.close()}),a(b).bind("keydown."+f,function(a){var b=a.keyCode;S&&K.escKey&&b===27&&(a.preventDefault(),X.close()),S&&K.arrowKey&&y[1]&&(b===37?(a.preventDefault(),H.click()):b===39&&(a.preventDefault(),G.click()))})},X.remove=function(){r.add(q).remove(),a("."+g).removeData(e).removeClass(g)},X.position=function(a,c){function g(a){u[0].style.width=x[0].style.width=t[0].style.width=a.style.width,C[0].style.height=C[1].style.height=t[0].style.height=v[0].style.height=w[0].style.height=a.style.height}var d=0,e=0;z.unbind("resize."+f),r.hide(),K.fixed&&!o?r.css({position:"fixed"}):(d=z.scrollTop(),e=z.scrollLeft(),r.css({position:"absolute"})),K.right!==!1?e+=Math.max(z.width()-K.w-O-M-Z(K.right,"x"),0):K.left!==!1?e+=Z(K.left,"x"):e+=Math.round(Math.max(z.width()-K.w-O-M,0)/2),K.bottom!==!1?d+=Math.max(b.documentElement.clientHeight-K.h-N-L-Z(K.bottom,"y"),0):K.top!==!1?d+=Z(K.top,"y"):d+=Math.round(Math.max(b.documentElement.clientHeight-K.h-N-L,0)/2),r.show(),a=r.width()===K.w+O&&r.height()===K.h+N?0:a||0,s[0].style.width=s[0].style.height="9999px",r.dequeue().animate({width:K.w+O,height:K.h+N,top:d,left:e},{duration:a,complete:function(){g(this),T=!1,s[0].style.width=K.w+O+M+"px",s[0].style.height=K.h+N+L+"px",c&&c(),setTimeout(function(){z.bind("resize."+f,X.position)},1)},step:function(){g(this)}})},X.resize=function(a){if(S){a=a||{},a.width&&(K.w=Z(a.width,"x")-O-M),a.innerWidth&&(K.w=Z(a.innerWidth,"x")),A.css({width:K.w}),a.height&&(K.h=Z(a.height,"y")-N-L),a.innerHeight&&(K.h=Z(a.innerHeight,"y"));if(!a.innerHeight&&!a.height){var b=A.wrapInner("<div style='overflow:auto'></div>").children();K.h=b.height(),b.replaceWith(b.children())}A.css({height:K.h}),X.position(K.transition==="none"?0:K.speed)}},X.prep=function(b){function h(){K.h=K.h||A.height(),K.h=K.mh&&K.mh<K.h?K.mh:K.h;return K.h}function g(){K.w=K.w||A.width(),K.w=K.mw&&K.mw<K.w?K.mw:K.w;return K.w}if(!!S){var c,d=K.transition==="none"?0:K.speed;A.remove(),A=Y("LoadedContent").append(b),A.hide().appendTo(B.show()).css({width:g(),overflow:K.scrolling?"auto":"hidden"}).css({height:h()}).prependTo(t),B.hide(),a(R).css({"float":"none"}),o&&a("select").not(r.find("select")).filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one(k,function(){this.style.visibility="inherit"}),c=function(){function o(){n&&r[0].style.removeAttribute("filter")}var b,c,g,h,i=y.length,k,l;!S||(l=function(){clearTimeout(W),C.hide(),ba(j,K.onComplete)},n&&R&&A.fadeIn(100),D.html(K.title).add(A).show(),i>1?(typeof K.current=="string"&&E.html(K.current.replace("{current}",Q+1).replace("{total}",i)).show(),G[K.loop||Q<i-1?"show":"hide"]().html(K.next),H[K.loop||Q?"show":"hide"]().html(K.previous),b=Q?y[Q-1]:y[i-1],g=Q<i-1?y[Q+1]:y[0],K.slideshow&&F.show(),K.preloading&&(h=a.data(g,e).href||g.href,c=a.data(b,e).href||b.href,h=a.isFunction(h)?h.call(g):h,c=a.isFunction(c)?c.call(b):c,$(h)&&(a("<img/>")[0].src=h),$(c)&&(a("<img/>")[0].src=c))):J.hide(),K.iframe?(k=a("<iframe/>").addClass(f+"Iframe")[0],K.fastIframe?l():a(k).one("load",l),k.name=f+ +(new Date),k.src=K.href,K.scrolling||(k.scrolling="no"),n&&(k.frameBorder=0,k.allowTransparency="true"),a(k).appendTo(A).one(m,function(){k.src="//about:blank"})):l(),K.transition==="fade"?r.fadeTo(d,1,o):o())},K.transition==="fade"?r.fadeTo(d,0,function(){X.position(0,c)}):X.position(d,c)}},X.load=function(b){var c,d,e=X.prep;T=!0,R=!1,P=y[Q],b||_(),ba(m),ba(i,K.onLoad),K.h=K.height?Z(K.height,"y")-N-L:K.innerHeight&&Z(K.innerHeight,"y"),K.w=K.width?Z(K.width,"x")-O-M:K.innerWidth&&Z(K.innerWidth,"x"),K.mw=K.w,K.mh=K.h,K.maxWidth&&(K.mw=Z(K.maxWidth,"x")-O-M,K.mw=K.w&&K.w<K.mw?K.w:K.mw),K.maxHeight&&(K.mh=Z(K.maxHeight,"y")-N-L,K.mh=K.h&&K.h<K.mh?K.h:K.mh),c=K.href,W=setTimeout(function(){C.show()},100),K.inline?(Y().hide().insertBefore(a(c)[0]).one(m,function(){a(this).replaceWith(A.children())}),e(a(c))):K.iframe?e(" "):K.html?e(K.html):$(c)?(a(R=new Image).addClass(f+"Photo").error(function(){K.title=!1,e(Y("Error").text("This image could not be loaded"))}).load(function(){var a;R.onload=null,K.scalePhotos&&(d=function(){R.height-=R.height*a,R.width-=R.width*a},K.mw&&R.width>K.mw&&(a=(R.width-K.mw)/R.width,d()),K.mh&&R.height>K.mh&&(a=(R.height-K.mh)/R.height,d())),K.h&&(R.style.marginTop=Math.max(K.h-R.height,0)/2+"px"),y[1]&&(Q<y.length-1||K.loop)&&(R.style.cursor="pointer",R.onclick=function(){X.next()}),n&&(R.style.msInterpolationMode="bicubic"),setTimeout(function(){e(R)},1)}),setTimeout(function(){R.src=c},1)):c&&B.load(c,K.data,function(b,c,d){e(c==="error"?Y("Error").text("Request unsuccessful: "+d.statusText):a(this).contents())})},X.next=function(){!T&&y[1]&&(Q<y.length-1||K.loop)&&(Q=Q<y.length-1?Q+1:0,X.load())},X.prev=function(){!T&&y[1]&&(Q||K.loop)&&(Q=Q?Q-1:y.length-1,X.load())},X.close=function(){S&&!U&&(U=!0,S=!1,ba(k,K.onCleanup),z.unbind("."+f+" ."+p),q.fadeTo(200,0),r.stop().fadeTo(300,0,function(){r.add(q).css({opacity:1,cursor:"auto"}).hide(),ba(m),A.remove(),setTimeout(function(){U=!1,ba(l,K.onClosed)},1)}))},X.element=function(){return a(P)},X.settings=d,V=function(a){a.button!==0&&typeof a.button!="undefined"||a.ctrlKey||a.shiftKey||a.altKey||(a.preventDefault(),bc(this))},a.fn.delegate?a(b).delegate("."+g,"click",V):a("."+g).live("click",V),a(X.init)})(jQuery,document,this);

$(document).ready(function(){
    $("a[rel='example1']").colorbox();
    $("#size_open").colorbox({width:"300px", inline:true, transition: "none", href:"#size_content"});
});


$(function () {

        $('.m-slider_mains').mSlider({
            easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay: 3000,                    // How long between slide transitions in AutoPlay mode
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            animationTime: 300,             // How long the slide transition takes
            hashTags: false,                 // Should links change the hashtag in the URL?
            buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
            startText: "Старт",             // Start text
            stopText: "Стоп"
        });

		$('.m-slider_cel').mSlider({
            easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay: 3000,                    // How long between slide transitions in AutoPlay mode
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            animationTime: 300,             // How long the slide transition takes
            hashTags: false,                 // Should links change the hashtag in the URL?
            buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
            startText: "Старт",             // Start text
            stopText: "Стоп",             // If true, and autoPlay is enabled, the show will pause on hover
            forward: '.m-slider_mains__arrow_f',  // Details at the top of the file on this use (advanced use)
            back: '.m-slider_mains__arrow_b'
        });

		$('.m-slider_mains__arrow_b').click(function(){
			el = $('.m-tab__item_active');
			next = $('.m-tab__item_active').next();
			el.removeClass('m-tab__item_active');
			if (next.length > 0) {
				next.addClass('m-tab__item_active');
			} else {
				$('.m-tab__item:first-child','.m-tab__content').addClass('m-tab__item_active');
			}
			
		});
		
		$('.m-slider_mains__arrow_f').click(function(){
			el = $('.m-tab__item_active');
			prev = $('.m-tab__item_active').prev();
			el.removeClass('m-tab__item_active');
			if (prev.length > 0) {
				prev.addClass('m-tab__item_active');
			} else {
				$('.m-tab__item:last-child','.m-tab__content').addClass('m-tab__item_active');
			}
		});

        $('.m-slider_brands').mSlider({
            easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay: 3000,                    // How long between slide transitions in AutoPlay mode
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            animationTime: 300,             // How long the slide transition takes
            hashTags: false,                 // Should links change the hashtag in the URL?
            buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
            forward: '.m-slider__arrow_f',  // Details at the top of the file on this use (advanced use)
            back: '.m-slider__arrow_b'
        });

    });


/************************************************
 * $import('../_matrioshka/m-/m-slider/m-slider.js');
 *************************************************/


jQuery.extend( jQuery.easing,
{
easeInQuad: function (x, t, b, c, d) {
    return c*(t/=d)*t + b;
},
easeOutQuad: function (x, t, b, c, d) {
    return -c *(t/=d)*(t-2) + b;
},
easeInOutQuad: function (x, t, b, c, d) {
    if ((t/=d/2) < 1) return c/2*t*t + b;
    return -c/2 * ((--t)*(t-2) - 1) + b;
},
easeInCubic: function (x, t, b, c, d) {
    return c*(t/=d)*t*t + b;
},
easeOutCubic: function (x, t, b, c, d) {
    return c*((t=t/d-1)*t*t + 1) + b;
},
easeInOutCubic: function (x, t, b, c, d) {
    if ((t/=d/2) < 1) return c/2*t*t*t + b;
    return c/2*((t-=2)*t*t + 2) + b;
},
easeInQuart: function (x, t, b, c, d) {
    return c*(t/=d)*t*t*t + b;
},
easeOutQuart: function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
easeInOutQuart: function (x, t, b, c, d) {
    if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
    return -c/2 * ((t-=2)*t*t*t - 2) + b;
},
easeInQuint: function (x, t, b, c, d) {
    return c*(t/=d)*t*t*t*t + b;
},
easeOutQuint: function (x, t, b, c, d) {
    return c*((t=t/d-1)*t*t*t*t + 1) + b;
},
easeInOutQuint: function (x, t, b, c, d) {
    if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
    return c/2*((t-=2)*t*t*t*t + 2) + b;
},
easeInSine: function (x, t, b, c, d) {
    return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
},
easeOutSine: function (x, t, b, c, d) {
    return c * Math.sin(t/d * (Math.PI/2)) + b;
},
easeInOutSine: function (x, t, b, c, d) {
    return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
},
easeInExpo: function (x, t, b, c, d) {
    return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
},
easeOutExpo: function (x, t, b, c, d) {
    return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
easeInOutExpo: function (x, t, b, c, d) {
    if (t==0) return b;
    if (t==d) return b+c;
    if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
    return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
},
easeInCirc: function (x, t, b, c, d) {
    return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
},
easeOutCirc: function (x, t, b, c, d) {
    return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
},
easeInOutCirc: function (x, t, b, c, d) {
    if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
    return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
},
easeInElastic: function (x, t, b, c, d) {
    var s=1.70158;var p=0;var a=c;
    if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
    if (a < Math.abs(c)) { a=c; var s=p/4; }
    else var s = p/(2*Math.PI) * Math.asin (c/a);
    return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
},
easeOutElastic: function (x, t, b, c, d) {
    var s=1.70158;var p=0;var a=c;
    if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
    if (a < Math.abs(c)) { a=c; var s=p/4; }
    else var s = p/(2*Math.PI) * Math.asin (c/a);
    return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
},
easeInOutElastic: function (x, t, b, c, d) {
    var s=1.70158;var p=0;var a=c;
    if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
    if (a < Math.abs(c)) { a=c; var s=p/4; }
    else var s = p/(2*Math.PI) * Math.asin (c/a);
    if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
    return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
},
easeInBack: function (x, t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    return c*(t/=d)*t*((s+1)*t - s) + b;
},
easeOutBack: function (x, t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
easeInOutBack: function (x, t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
},
easeInBounce: function (x, t, b, c, d) {
    return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
},
easeOutBounce: function (x, t, b, c, d) {
    if ((t/=d) < (1/2.75)) {
        return c*(7.5625*t*t) + b;
    } else if (t < (2/2.75)) {
        return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
    } else if (t < (2.5/2.75)) {
        return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
    } else {
        return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
    }
},
easeInOutBounce: function (x, t, b, c, d) {
    if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
    return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
}
});


(function($){

$.mSlider = function(el, options){
    // To avoid scope issues, use 'base' instead of 'this'
    // to reference this class from internal events and functions.
    var base = this;

    // Access to jQuery and DOM versions of element
    base.$el = $(el);
    base.el = el;

    // Set up a few defaults
    base.currentPage = 1;
    base.timer = null;
    base.playing = false;

    // Add a reverse reference to the DOM object
    base.$el.data("mSlider", base);

    base.init = function(){
        base.options = $.extend({},$.mSlider.defaults, options);

        // Cache existing DOM elements for later
        base.$wrapper = base.$el.find('> div').css('overflow', 'hidden');
        base.$slider  = base.$wrapper.find('> .m-slider__cadre');
        base.$items   = base.$slider.find('> .m-slider__item');
        base.$single  = base.$items.filter(':first');

        // Build the navigation if needed
        if(base.options.buildNavigation) base.buildNavigation();

        // Get the details
        base.singleWidth = base.$single.outerWidth();
        base.pages = base.$items.length;

        // Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        // This supports the "infinite" scrolling
        base.$items.filter(':last' ).after(base.$items.clone());



        /*base.$items.filter(':first').before(base.$items.filter(':last').clone());
        base.$items.filter(':last' ).after(base.$items.filter(':first').clone());*/
        // We just added two items, time to re-cache the list
        base.$items = base.$slider.find('> .m-slider__item'); // reselect

        // Setup our forward/backward navigation
        base.buildNextBackButtons();

        // If autoPlay functionality is included, then initialize the settings
        if(base.options.autoPlay) {
            base.playing = !base.options.startStopped; // Sets the playing variable to false if startStopped is true
            base.buildAutoPlay();
        };

        // If pauseOnHover then add hover effects
        if(base.options.pauseOnHover) {
            base.$el.hover(function(){
                base.clearTimer();
            }, function(){
                base.startStop(base.playing);
            });
        }

        // If a hash can not be used to trigger the plugin, then go to page 1
        if((base.options.hashTags == true && !base.gotoHash()) || base.options.hashTags == false){
            base.setCurrentPage(1);
        };
    };

    base.gotoPage = function(page, autoplay){
        // When autoplay isn't passed, we stop the timer
        if(autoplay !== true) autoplay = false;
        if(!autoplay) base.startStop(false);

        if(typeof(page) == "undefined" || page == null) {
            page = 1;
            base.setCurrentPage(1);
        };

        // Just check for bounds
        if(page > base.pages + 1) page = base.pages;
        if(page < 0 ) page = 1;

        var dir = page < base.currentPage ? -1 : 1,
            n = Math.abs(base.currentPage - page),
            left = base.singleWidth * dir * n;

        base.$wrapper.filter(':not(:animated)').animate({
            scrollLeft : '+=' + left
        }, base.options.animationTime, base.options.easing, function () {
            if (page == 0) {
                base.$wrapper.scrollLeft(base.singleWidth * base.pages);
                page = base.pages;
            } else if (page > base.pages) {
                base.$wrapper.scrollLeft(base.singleWidth);
                // reset back to start position
                page = 1;
            };
            base.setCurrentPage(page);

        });
    };

    base.setCurrentPage = function(page, move){
        // Set visual
        if(base.options.buildNavigation){
            base.$nav.find('.m-slider__link_active').removeClass('m-slider__link_active');
            $(base.$navLinks[page - 1]).addClass('m-slider__link_active');
        };

        // Only change left if move does not equal false
        if(move !== false) base.$wrapper.scrollLeft(base.singleWidth * page);

        // Update local variable
        base.currentPage = page;
    };

    base.goForward = function(autoplay){
        if(autoplay !== true) autoplay = false;
        base.gotoPage(base.currentPage + 1, autoplay);
    };

    base.goBack = function(){
        base.gotoPage(base.currentPage - 1);
    };

    // This method tries to find a hash that matches panel-X
    // If found, it tries to find a matching item
    // If that is found as well, then that item starts visible
    base.gotoHash = function(){
        if(/^#?panel-\d+$/.test(window.location.hash)){
            var index = parseInt(window.location.hash.substr(7));
            var $item = base.$items.filter(':eq(' + index + ')');
            if($item.length != 0){
                base.setCurrentPage(index);
                return true;
            };
        };
        return false; // A item wasn't found;
    };

    // Creates the numbered navigation links
    base.buildNavigation = function(){
        base.$nav = $("<div class='m-slider__thumb'></div>").appendTo(base.$el);
        base.$items.each(function(i,el){
            var index = i + 1;
            var $a = $("<a class='m-slider__link' href='#'></a>");

            // If a formatter function is present, use it
            if( typeof(base.options.navigationFormatter) == "function"){
                $a.html(base.options.navigationFormatter(index, $(this)));
            } else {
                $a.text(index);
            }
            $a.click(function(e){
                base.gotoPage(index);

                if (base.options.hashTags)
                    base.setHash('panel-' + index);

                e.preventDefault();
            });
            base.$nav.append($a);
        });
        base.$navLinks = base.$nav.find('> .m-slider__link');
    };


    // Creates the Forward/Backward buttons
    base.buildNextBackButtons = function(){
        var $forward = $(base.options.forward),
            $back    = $(base.options.back);

        // Bind to the forward and back buttons
        $back.click(function(e){
            base.goBack();
            e.preventDefault();
        });

        $forward.click(function(e){
            base.goForward();
            e.preventDefault();
        });

        // Append elements to page
        /*base.$wrapper.after($back).after($forward);*/
    };

    // Creates the Start/Stop button
    base.buildAutoPlay = function(){

        base.$startStop = $("<a href='javascript:void(0)' class='m-slider__start-button'></a>").html(base.playing ? base.options.stopText :  base.options.startText);
        base.$el.append(base.$startStop);
        base.$startStop.click(function(e){
            base.startStop(!base.playing);
            e.preventDefault();
        });

        // Use the same setting, but trigger the start;
        base.startStop(base.playing);
    };

    // Handles stopping and playing the slideshow
    // Pass startStop(false) to stop and startStop(true) to play
    base.startStop = function(playing){
        if(playing !== true) playing = false; // Default if not supplied is false

        // Update variable
        base.playing = playing;

        // Toggle playing and text
        if(base.options.autoPlay) base.$startStop.toggleClass("m-slider__start-button_on", playing).html( playing ? base.options.stopText : base.options.startText );

        if(playing){
            base.clearTimer(); // Just in case this was triggered twice in a row
            base.timer = window.setInterval(function(){
                base.goForward(true);
            }, base.options.delay);
        } else {
            base.clearTimer();
        };
    };

    base.clearTimer = function(){
        // Clear the timer only if it is set
        if(base.timer) window.clearInterval(base.timer);
    };

    // Taken from AJAXY jquery.history Plugin
    base.setHash = function ( hash ) {
        // Write hash
        if ( typeof window.location.hash !== 'undefined' ) {
            if ( window.location.hash !== hash ) {
                window.location.hash = hash;
            };
        } else if ( location.hash !== hash ) {
            location.hash = hash;
        };

        // Done
        return hash;
    };
    // <-- End AJAXY code


    // Trigger the initialization
    base.init();
};


$.mSlider.defaults = {
    easing: "swing",                // Anything other than "linear" or "swing" requires the easing plugin
    autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
    startStopped: false,            // If autoPlay is on, this can force it to start stopped
    delay: 3000,                    // How long between slide transitions in AutoPlay mode
    animationTime: 600,             // How long the slide transition takes
    hashTags: true,                 // Should links change the hashtag in the URL?
    buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
    pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
    startText: "Start",             // Start text
    stopText: "Stop",               // Stop text
    navigationFormatter: null,      // Details at the top of the file on this use (advanced use)
    forward:  null,
    back:  null
};


$.fn.mSlider = function(options){
    if(typeof(options) == "object"){
        return this.each(function(i){
            (new $.mSlider(this, options));

            // This plugin supports multiple instances, but only one can support hash-tag support
            // This disables hash-tags on all items but the first one
            options.hashTags = false;
        });
    } else if (typeof(options) == "number") {

        return this.each(function(i){
            var anySlide = $(this).data('mSlider');
            if(anySlide){
                anySlide.gotoPage(options);
            }
        });
    }
};


})(jQuery);

/************************************************
 * $import('../_matrioshka/m-/m-slider/m-slider.js');
 *************************************************/




/************************************************
 * $import('../_matrioshka/m-/m-tab/m-tab.js');
 *************************************************/
$(document).ready(function(){
    $('.m-tab__link').click(function(){

        $('.m-tab__link').removeClass('m-tab__link_active');
        $('.m-tab__item').removeClass('m-tab__item_active');

        $(this).addClass('m-tab__link_active');
        var index = $('.m-tab__link').index(this);

        $($('.m-tab__item')[index]).addClass('m-tab__item_active');

    });
});

/************************************************
 * $import('../_matrioshka/m-/m-tab/m-tab.js');
 *************************************************/



/************************************************
 * $import('../_matrioshka/m-/m-article/m-article.js');
 *************************************************/
$('.m-article table tr:nth-child(even)').addClass('i-scope_tr');
/************************************************
 * $import('../_matrioshka/m-/m-article/m-article.js');
 *************************************************/



/************************************************
 * $import('../_matrioshka/i-/i-mouse/i-mouse.js');
 *************************************************/
$(document).mousemove(function(){$('html').addClass('i-mouse');$(this).unbind("mousemove");});
/************************************************
 * $import('../_matrioshka/i-/i-mouse/i-mouse.js');
 *************************************************/



/************************************************
 * $import('../_matrioshka/m-/m-popup/m-popup.js');
 *************************************************/
$(document).ready(function(){
   $('.m-popup__button').click(function(){
        if ($('.m-popup').hasClass('m-popup_on')) {
            $('.m-popup').removeClass('m-popup_on');
        } else {
            $('.m-popup').addClass('m-popup_on');

            var p_height = $('.m-popup__block').height();
            var p_width = $('.m-popup__block').width();

            $('.m-popup__block').css('margin-left', -p_width / 2);
            $('.m-popup__block').css('margin-top', -p_height / 2);
        }
    });
});
/************************************************
 * $import('../_matrioshka/m-/m-popup/m-popup.js');
 *************************************************/
