/* Échec de l'agrandissement. Renvoi du contenu non agrandi.
(1046,13-27): run-time error JS1300: Strict-mode does not allow assignment to undefined variables: imagesCarousel
 */
$(document).ready(function () {
    $(".reserver-button").click(function () {
        $('.validation-retrait').css('display', 'block');
    });
});;
'use strict';

var ProductReveal = /** @class */ (function () {
    function ProductReveal(wrapper) {
        this.init();
    }
    /** Init **/
    ProductReveal.prototype.init = function () {
        this.initCarousel();
        this.addEvents();
        //this.test();
    };

    ProductReveal.prototype.initCarousel = function () {
        $(".o-products .owl-carousel").each(function (index, item) {
            var responsive = {
                600: {
                    items: 2,
                    loop: ($(item).find('.item').length > 2),
                    mouseDrag: ($(item).find('.item').length > 2),
                    touchDrag: ($(item).find('.item').length > 2),
                    margin: 10,
                    stagePadding: 40,
                    dots: false,
                    nav: false,
                },
                1020: {
                    items: 2,
                    loop: ($(item).find('.item').length > 3),
                    mouseDrag: ($(item).find('.item').length > 3),
                    touchDrag: ($(item).find('.item').length > 3),
                    dots: false,
                    nav: false,
                },
                1200: {
                    items: 4,
                    loop: ($(item).find('.item').length > 4),
                    mouseDrag: ($(item).find('.item').length > 4),
                    touchDrag: ($(item).find('.item').length > 4),
                    stagePadding: 0,
                    margin: 10,
                }
            };

            $(item).owlCarousel({
                items: 1,
                stagePadding: 30,
                loop: true,
                margin: 10,
                nav: true,
                navText: ['4', '5'],
                dots: true,
                mouseDrag: true,
                touchDrag: true,
                responsive: responsive
            });

        });
    };

    /** End Init **/

    /** Events **/
    ProductReveal.prototype.addEvents = function () {
        var self = this;

        $('#popin-jewellery-part .a-button').unbind('click').bind("click", function (e) {
            e.preventDefault();
            var $this, $parent, data;
            $this = $(e.currentTarget);
            $parent = $this.parents(".m-option");
            if ($parent.hasClass('-active')) {
                data = { "ref": $this.attr('data-reference'), "line": $this.attr('data-line-number'), "ecrin": $this.attr('data-ecrin'), "option": $this.attr('data-option-id') };
                self.deleteEcrinFromProductReveal(data);
            } else {
                data = { "ref": $this.attr('data-reference'), "line": $this.attr('data-line-number'), "ecrin": $this.attr('data-ecrin') };
                self.addEcrinFromProductReveal(data);
            }
        });
       
        $('#popin-warranty-part .a-button').unbind('click').bind("click", function (e) {
            e.preventDefault();
            var $this, $parent, data;
            $this = $(e.currentTarget);
            $parent = $this.parents(".m-option");
            if ($parent.hasClass('-active')) {
                data = { "ref": $this.attr('data-reference'), "line": $this.attr('data-line-number'), "warranty": $this.attr('data-warranty-reference'), "option": $this.attr('data-option-id') };
               
                self.deleteWarrantyExtensionFromProductReveal(data);
            } else {
                data = { "ref": $this.attr('data-reference'), "line": $this.attr('data-line-number'), "warranty": $this.attr('data-warranty-reference') };
                self.addWarrantyExtensionFromProductReveal(data);
               
            }
        });
        $('.add-product-from-carousel .a-button__span').unbind('click').bind("click", function (e) {
            e.preventDefault();
            var $this = $(e.currentTarget);
            var $parentButton = $this.parent('.add-product-from-carousel');
            var data = { "itemRef": $parentButton.attr('data-itemRef'), "target": $parentButton }
            var itemRef = $parentButton.data('itemref');


            if (itemRef !== undefined && !$parentButton.hasClass("-added")) {
                self.addProductFromMerchandisingAreas(data);
            }
        });

    };
    /** End Events **/

    /* AJAX Functions */
    ProductReveal.prototype.addEcrinFromProductReveal = function (data) {
        var self = this;
        var reference = data.ref;
        var lineNumber = data.line;
        var ecrin = data.ecrin;
        $.ajax(
            {
                url: '/CartAction/AddJewelleryBox',
                contentType: "application/json",
                data: {
                    reference: reference,
                    lineNumber: lineNumber,
                    ecrin: ecrin,
                    forPopin: true
                },
                beforeSend: function (e) {
                    Foundation.libs.common.showPreloader();
                },
                complete: function (result) {
                    if (result.responseJSON.IsValid == true) {
                        $('#popin-jewellery-part').html(result.responseJSON._SectionProductJewelleryBoxLine);
                        self.addEvents();

                        $(document).foundation('mastertag', 'track_tc_event',
                        {
                            obj: this,
                            trigger: 'up_sell',
                            options: {
                                category: 'up-sell',
                                action: 'ecrin',
                                label: 'pop-in ajout panier',
                                value: ''
                            }
                        });

                        Foundation.libs.common.refreshMasterTagData(result._MasterTagJson, true);
                        Foundation.libs.common.refreshMasterTag();
                    }                                      
                    Foundation.libs.common.hidePreloader();
                }
            }
        ).fail(function (result) {           
            Foundation.libs.common.hidePreloader();
        });
    }

    ProductReveal.prototype.deleteEcrinFromProductReveal = function (data) {
        var self = this;
        var reference = data.ref;
        var lineNumber = data.line;
        var ecrin = data.ecrin;
        var optionId = data.option;
        $.ajax(
            {
                url: '/CartAction/RemoveJewelleryBox',
                contentType: "application/json",
                data: {
                    reference: reference,
                    lineNumber: lineNumber,
                    ecrin: ecrin,
                    optionId: optionId,
                    forPopin: true
                },
                beforeSend: function (e) {
                    Foundation.libs.common.showPreloader();
                },
                complete: function (result) {
                    
                    if (result.responseJSON.IsValid == true) {
                        $('#popin-jewellery-part').html(result.responseJSON._SectionProductJewelleryBoxLine);
                        self.addEvents();

                        Foundation.libs.common.refreshMasterTagData(result._MasterTagJson, true);
                        Foundation.libs.common.refreshMasterTag();
                    }
                    else {

                    }
                    Foundation.libs.common.hidePreloader();
                }
            }
        ).fail(function (result) {
          
            Foundation.libs.common.hidePreloader();
        });
    },

    ProductReveal.prototype.addWarrantyExtensionFromProductReveal = function (data) {
    var self = this;
        var reference = data.ref;
        var lineNumber = data.line;
        var warrantyReference = data.warranty;
        $.ajax(
            {
                url: '/CartAction/AddWarrantyExtension',
                contentType: "application/json",
                data: {
                    reference: reference,
                    lineNumber: lineNumber,
                    warrantyReference: warrantyReference,
                    forPopin: true
                },
                beforeSend: function (e) {
                    Foundation.libs.common.showPreloader();
                },
                complete: function (result) {
                    if (result.responseJSON.IsValid == true) {
                        $('#popin-warranty-part').html(result.responseJSON._SectionProductWarrantyLine);
                        self.addEvents();

                        $(document).foundation('mastertag', 'track_tc_event',
                        {
                            obj: this,
                            trigger: 'up_sell',
                            options: {
                                category: 'up-sell',
                                action: 'garantie',
                                label: 'pop-in ajout panier',
                                value: ''
                            }
                        });

                        Foundation.libs.common.refreshMasterTagData(result._MasterTagJson, true);
                        Foundation.libs.common.refreshMasterTag();
                    }
                    
                    Foundation.libs.common.hidePreloader();
                }
            }
        ).fail(function (result) {
               
            Foundation.libs.common.hidePreloader();
        });
        },

    ProductReveal.prototype.deleteWarrantyExtensionFromProductReveal = function (data) {
    var self = this;
        var reference = data.ref;
        var lineNumber = data.line;
        var warrantyReference = data.warranty;
        var optionId = data.option;
        $.ajax(
            {
                url: '/CartAction/RemoveWarrantyExtension',
                contentType: "application/json",
                data: {
                    reference: reference,
                    lineNumber: lineNumber,
                    warrantyReference: warrantyReference,
                    optionId: optionId,
                    forPopin: true
                },
                beforeSend: function (e) {
                    Foundation.libs.common.showPreloader();
                },
                complete: function (result) {
                    if (result.responseJSON.IsValid == true) {
                        $('#popin-warranty-part').html(result.responseJSON._SectionProductWarrantyLine);
                        self.addEvents();

                        Foundation.libs.common.refreshMasterTagData(result._MasterTagJson, true);
                        Foundation.libs.common.refreshMasterTag();
                    }
                       
                    Foundation.libs.common.hidePreloader();
                }
            }
        ).fail(function (result) {
            //Foundation.libs.cart.updateCart(result.responseJSON);
            Foundation.libs.common.hidePreloader();
        });
    },
        
    ProductReveal.prototype.addProductFromMerchandisingAreas = function (data) {
        var reference = data.itemRef;
        var $button = data.target;

        $.ajax(
            {
                url: '/CartAction/AddItemFromPopinProductMerchAreas',
                contentType: "application/json",
                data: {
                    reference: reference
                },
                beforeSend: function (e) {
                    Foundation.libs.common.showPreloader();
                },
                success: function (result) {

                    if (result.IsValid == true) {
                        Foundation.libs.common.clearLightCart();
                        $button.toggleClass('-added');

                        setTimeout(function () {
                            $button.removeClass("-added");
                        }, 3000);

                        Foundation.libs.common.refreshMasterTagData(result._MasterTagJson, true);
                        Foundation.libs.common.refreshMasterTag();

                        if (typeof (tc_vars) !== "undefined" && typeof (tc_vars.order_products) !== "undefined") {
                            const order_product = tc_vars.order_products.find(function (p) {
                                return p.product_id === reference;
                            });

                            if (typeof (order_product) !== "undefined") {
                                const event = {
                                    obj: "",
                                    trigger: 'ajout_panier',
                                    options: {
                                        category: "panier",
                                        action: "ajout produit",
                                        label: order_product.product_name + ' - ' + order_product.product_id,
                                        value: order_product.product_unitprice_ati,
                                        product_brand: order_product.product_trademark,
                                        product_cat1: order_product.product_cat1,
                                        product_cat2: order_product.product_cat2,
                                        product_cat3: order_product.product_cat3,
                                        product_category: order_product.product_category,
                                        product_currency: order_product.product_currency,
                                        product_discount_tf: order_product.product_discount_tf,
                                        product_discount_ati: order_product.product_discount_ati,
                                        product_engraving: order_product.product_engraving,
                                        product_gravable: order_product.product_gravable,
                                        product_id: order_product.product_id,
                                        product_name: order_product.product_name,
                                        product_promo: order_product.product_promo,
                                        product_promo_label: order_product.product_promo_label,
                                        product_quantity: order_product.product_quantity,
                                        product_rating: order_product.product_rating,
                                        product_size: order_product.product_size,
                                        product_trademark: order_product.product_trademark,
                                        product_unitprice_ati: order_product.product_unitprice_ati,
                                        product_unitprice_tf: order_product.product_unitprice_tf,
                                    }
                                };

                                $(document).foundation('mastertag', 'track_tc_event', event);
                            }
                        }

                        Foundation.libs.common.hidePreloader();
                    } else {
                        if (result.UrlFicheProduit != null) {
                            window.location.href = result.UrlFicheProduit;
                        }
                    }
                      
                }
            }
        ).fail(function (result) {
            Foundation.libs.common.hidePreloader();
        });
        }

    /* End AJAX Functions */

    return ProductReveal;
}());







;
/**
 * @license jquery.panzoom.js v2.0.5
 * Updated: Thu Apr 03 2014
 * Add pan and zoom functionality to any element
 * Copyright (c) 2014 timmy willison
 * Released under the MIT license
 * https://github.com/timmywil/jquery.panzoom/blob/master/MIT-License.txt
 */
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(c){return b(a,c)}):"object"==typeof exports?b(a,require("jquery")):b(a,a.jQuery)}("undefined"!=typeof window?window:this,function(a,b){"use strict";function c(a,b){for(var c=a.length;--c;)if(+a[c]!==+b[c])return!1;return!0}function d(a){var c={range:!0,animate:!0};return"boolean"==typeof a?c.animate=a:b.extend(c,a),c}function e(a,c,d,e,f,g,h,i,j){this.elements="array"===b.type(a)?[+a[0],+a[2],+a[4],+a[1],+a[3],+a[5],0,0,1]:[a,c,d,e,f,g,h||0,i||0,j||1]}function f(a,b,c){this.elements=[a,b,c]}function g(a,c){if(!(this instanceof g))return new g(a,c);1!==a.nodeType&&b.error("Panzoom called on non-Element node"),b.contains(document,a)||b.error("Panzoom element must be attached to the document");var d=b.data(a,l);if(d)return d;this.options=c=b.extend({},g.defaults,c),this.elem=a;var e=this.$elem=b(a);this.$set=c.$set&&c.$set.length?c.$set:e,this.$doc=b(a.ownerDocument||document),this.$parent=e.parent(),this.isSVG=p.test(a.namespaceURI)&&"svg"!==a.nodeName.toLowerCase(),this.panning=!1,this._buildTransform(),this._transform=!this.isSVG&&b.cssProps.transform.replace(o,"-$1").toLowerCase(),this._buildTransition(),this.resetDimensions();var f=b(),h=this;b.each(["$zoomIn","$zoomOut","$zoomRange","$reset"],function(a,b){h[b]=c[b]||f}),this.enable(),b.data(a,l,this)}var h="over out down up move enter leave cancel".split(" "),i=b.extend({},b.event.mouseHooks),j={};if(a.PointerEvent)b.each(h,function(a,c){b.event.fixHooks[j[c]="pointer"+c]=i});else{var k=i.props;i.props=k.concat(["touches","changedTouches","targetTouches","altKey","ctrlKey","metaKey","shiftKey"]),i.filter=function(a,b){var c,d=k.length;if(!b.pageX&&b.touches&&(c=b.touches[0]))for(;d--;)a[k[d]]=c[k[d]];return a},b.each(h,function(a,c){if(2>a)j[c]="mouse"+c;else{var d="touch"+("down"===c?"start":"up"===c?"end":c);b.event.fixHooks[d]=i,j[c]=d+" mouse"+c}})}b.pointertouch=j;var l="__pz__",m=Array.prototype.slice,n=!!a.PointerEvent,o=/([A-Z])/g,p=/^http:[\w\.\/]+svg$/,q=/^inline/,r="(\\-?[\\d\\.e]+)",s="\\,?\\s*",t=new RegExp("^matrix\\("+r+s+r+s+r+s+r+s+r+s+r+"\\)$");return e.prototype={x:function(a){var b=a instanceof f,c=this.elements,d=a.elements;return b&&3===d.length?new f(c[0]*d[0]+c[1]*d[1]+c[2]*d[2],c[3]*d[0]+c[4]*d[1]+c[5]*d[2],c[6]*d[0]+c[7]*d[1]+c[8]*d[2]):d.length===c.length?new e(c[0]*d[0]+c[1]*d[3]+c[2]*d[6],c[0]*d[1]+c[1]*d[4]+c[2]*d[7],c[0]*d[2]+c[1]*d[5]+c[2]*d[8],c[3]*d[0]+c[4]*d[3]+c[5]*d[6],c[3]*d[1]+c[4]*d[4]+c[5]*d[7],c[3]*d[2]+c[4]*d[5]+c[5]*d[8],c[6]*d[0]+c[7]*d[3]+c[8]*d[6],c[6]*d[1]+c[7]*d[4]+c[8]*d[7],c[6]*d[2]+c[7]*d[5]+c[8]*d[8]):!1},inverse:function(){var a=1/this.determinant(),b=this.elements;return new e(a*(b[8]*b[4]-b[7]*b[5]),a*-(b[8]*b[1]-b[7]*b[2]),a*(b[5]*b[1]-b[4]*b[2]),a*-(b[8]*b[3]-b[6]*b[5]),a*(b[8]*b[0]-b[6]*b[2]),a*-(b[5]*b[0]-b[3]*b[2]),a*(b[7]*b[3]-b[6]*b[4]),a*-(b[7]*b[0]-b[6]*b[1]),a*(b[4]*b[0]-b[3]*b[1]))},determinant:function(){var a=this.elements;return a[0]*(a[8]*a[4]-a[7]*a[5])-a[3]*(a[8]*a[1]-a[7]*a[2])+a[6]*(a[5]*a[1]-a[4]*a[2])}},f.prototype.e=e.prototype.e=function(a){return this.elements[a]},g.rmatrix=t,g.events=b.pointertouch,g.defaults={eventNamespace:".panzoom",transition:!0,cursor:"move",disablePan:!1,disableZoom:!1,increment:.3,minScale:.4,maxScale:5,rangeStep:.05,duration:200,easing:"ease-in-out",contain:!1},g.prototype={constructor:g,instance:function(){return this},enable:function(){this._initStyle(),this._bind(),this.disabled=!1},disable:function(){this.disabled=!0,this._resetStyle(),this._unbind()},isDisabled:function(){return this.disabled},destroy:function(){this.disable(),b.removeData(this.elem,l)},resetDimensions:function(){var a=this.$parent;this.container={width:a.innerWidth(),height:a.innerHeight()};var c,d=a.offset(),e=this.elem,f=this.$elem;this.isSVG?(c=e.getBoundingClientRect(),c={left:c.left-d.left,top:c.top-d.top,width:c.width,height:c.height,margin:{left:0,top:0}}):c={left:b.css(e,"left",!0)||0,top:b.css(e,"top",!0)||0,width:f.innerWidth(),height:f.innerHeight(),margin:{top:b.css(e,"marginTop",!0)||0,left:b.css(e,"marginLeft",!0)||0}},c.widthBorder=b.css(e,"borderLeftWidth",!0)+b.css(e,"borderRightWidth",!0)||0,c.heightBorder=b.css(e,"borderTopWidth",!0)+b.css(e,"borderBottomWidth",!0)||0,this.dimensions=c},reset:function(a){a=d(a);var b=this.setMatrix(this._origTransform,a);a.silent||this._trigger("reset",b)},resetZoom:function(a){a=d(a);var b=this.getMatrix(this._origTransform);a.dValue=b[3],this.zoom(b[0],a)},resetPan:function(a){var b=this.getMatrix(this._origTransform);this.pan(b[4],b[5],d(a))},setTransform:function(a){for(var c=this.isSVG?"attr":"style",d=this.$set,e=d.length;e--;)b[c](d[e],"transform",a)},getTransform:function(a){var c=this.$set,d=c[0];return a?this.setTransform(a):a=b[this.isSVG?"attr":"style"](d,"transform"),"none"===a||t.test(a)||this.setTransform(a=b.css(d,"transform")),a||"none"},getMatrix:function(a){var b=t.exec(a||this.getTransform());return b&&b.shift(),b||[1,0,0,1,0,0]},setMatrix:function(a,c){if(!this.disabled){c||(c={}),"string"==typeof a&&(a=this.getMatrix(a));var d,e,f,g,h,i,j,k,l,m,n=+a[0],o=this.$parent,p="undefined"!=typeof c.contain?c.contain:this.options.contain;return p&&(d=this._checkDims(),e=this.container,l=d.width+d.widthBorder,m=d.height+d.heightBorder,f=(l*Math.abs(n)-e.width)/2,g=(m*Math.abs(n)-e.height)/2,j=d.left+d.margin.left,k=d.top+d.margin.top,"invert"===p?(h=l>e.width?l-e.width:0,i=m>e.height?m-e.height:0,f+=(e.width-l)/2,g+=(e.height-m)/2,a[4]=Math.max(Math.min(a[4],f-j),-f-j-h),a[5]=Math.max(Math.min(a[5],g-k),-g-k-i+d.heightBorder)):(g+=d.heightBorder/2,h=e.width>l?e.width-l:0,i=e.height>m?e.height-m:0,"center"===o.css("textAlign")&&q.test(b.css(this.elem,"display"))?h=0:f=g=0,a[4]=Math.min(Math.max(a[4],f-j),-f-j+h),a[5]=Math.min(Math.max(a[5],g-k),-g-k+i))),"skip"!==c.animate&&this.transition(!c.animate),c.range&&this.$zoomRange.val(n),this.setTransform("matrix("+a.join(",")+")"),c.silent||this._trigger("change",a),a}},isPanning:function(){return this.panning},transition:function(a){if(this._transition)for(var c=a||!this.options.transition?"none":this._transition,d=this.$set,e=d.length;e--;)b.style(d[e],"transition")!==c&&b.style(d[e],"transition",c)},pan:function(a,b,c){if(!this.options.disablePan){c||(c={});var d=c.matrix;d||(d=this.getMatrix()),c.relative&&(a+=+d[4],b+=+d[5]),d[4]=a,d[5]=b,this.setMatrix(d,c),c.silent||this._trigger("pan",d[4],d[5])}},zoom:function(a,c){"object"==typeof a?(c=a,a=null):c||(c={});var d=b.extend({},this.options,c);if(!d.disableZoom){var g=!1,h=d.matrix||this.getMatrix();"number"!=typeof a&&(a=+h[0]+d.increment*(a?-1:1),g=!0),a>d.maxScale?a=d.maxScale:a<d.minScale&&(a=d.minScale);var i=d.focal;if(i&&!d.disablePan){var j=this._checkDims(),k=i.clientX,l=i.clientY;this.isSVG||(k-=(j.width+j.widthBorder)/2,l-=(j.height+j.heightBorder)/2);var m=new f(k,l,1),n=new e(h),o=this.parentOffset||this.$parent.offset(),p=new e(1,0,o.left-this.$doc.scrollLeft(),0,1,o.top-this.$doc.scrollTop()),q=n.inverse().x(p.inverse().x(m)),r=a/h[0];n=n.x(new e([r,0,0,r,0,0])),m=p.x(n.x(q)),h[4]=+h[4]+(k-m.e(0)),h[5]=+h[5]+(l-m.e(1))}h[0]=a,h[3]="number"==typeof d.dValue?d.dValue:a,this.setMatrix(h,{animate:"boolean"==typeof d.animate?d.animate:g,range:!d.noSetRange}),d.silent||this._trigger("zoom",h[0],d)}},option:function(a,c){var d;if(!a)return b.extend({},this.options);if("string"==typeof a){if(1===arguments.length)return void 0!==this.options[a]?this.options[a]:null;d={},d[a]=c}else d=a;this._setOptions(d)},_setOptions:function(a){b.each(a,b.proxy(function(a,c){switch(a){case"disablePan":this._resetStyle();case"$zoomIn":case"$zoomOut":case"$zoomRange":case"$reset":case"disableZoom":case"onStart":case"onChange":case"onZoom":case"onPan":case"onEnd":case"onReset":case"eventNamespace":this._unbind()}switch(this.options[a]=c,a){case"disablePan":this._initStyle();case"$zoomIn":case"$zoomOut":case"$zoomRange":case"$reset":this[a]=c;case"disableZoom":case"onStart":case"onChange":case"onZoom":case"onPan":case"onEnd":case"onReset":case"eventNamespace":this._bind();break;case"cursor":b.style(this.elem,"cursor",c);break;case"minScale":this.$zoomRange.attr("min",c);break;case"maxScale":this.$zoomRange.attr("max",c);break;case"rangeStep":this.$zoomRange.attr("step",c);break;case"startTransform":this._buildTransform();break;case"duration":case"easing":this._buildTransition();case"transition":this.transition();break;case"$set":c instanceof b&&c.length&&(this.$set=c,this._initStyle(),this._buildTransform())}},this))},_initStyle:function(){var a={"backface-visibility":"hidden","transform-origin":this.isSVG?"0 0":"50% 50%"};this.options.disablePan||(a.cursor=this.options.cursor),this.$set.css(a);var c=this.$parent;c.length&&!b.nodeName(c[0],"body")&&(a={overflow:"hidden"},"static"===c.css("position")&&(a.position="relative"),c.css(a))},_resetStyle:function(){this.$elem.css({cursor:"",transition:""}),this.$parent.css({overflow:"",position:""})},_bind:function(){var a=this,c=this.options,d=c.eventNamespace,e=n?"pointerdown"+d:"touchstart"+d+" mousedown"+d,f=n?"pointerup"+d:"touchend"+d+" click"+d,h={},i=this.$reset,j=this.$zoomRange;if(b.each(["Start","Change","Zoom","Pan","End","Reset"],function(){var a=c["on"+this];b.isFunction(a)&&(h["panzoom"+this.toLowerCase()+d]=a)}),c.disablePan&&c.disableZoom||(h[e]=function(b){var d;("touchstart"===b.type?!(d=b.touches)||(1!==d.length||c.disablePan)&&2!==d.length:c.disablePan||1!==b.which)||(b.preventDefault(),b.stopPropagation(),a._startMove(b,d))}),this.$elem.on(h),i.length&&i.on(f,function(b){b.preventDefault(),a.reset()}),j.length&&j.attr({step:c.rangeStep===g.defaults.rangeStep&&j.attr("step")||c.rangeStep,min:c.minScale,max:c.maxScale}).prop({value:this.getMatrix()[0]}),!c.disableZoom){var k=this.$zoomIn,l=this.$zoomOut;k.length&&l.length&&(k.on(f,function(b){b.preventDefault(),a.zoom()}),l.on(f,function(b){b.preventDefault(),a.zoom(!0)})),j.length&&(h={},h[(n?"pointerdown":"mousedown")+d]=function(){a.transition(!0)},h["change"+d]=function(){a.zoom(+this.value,{noSetRange:!0})},j.on(h))}},_unbind:function(){this.$elem.add(this.$zoomIn).add(this.$zoomOut).add(this.$reset).off(this.options.eventNamespace)},_buildTransform:function(){return this._origTransform=this.getTransform(this.options.startTransform)},_buildTransition:function(){if(this._transform){var a=this.options;this._transition=this._transform+" "+a.duration+"ms "+a.easing}},_checkDims:function(){var a=this.dimensions;return a.width&&a.height||this.resetDimensions(),this.dimensions},_getDistance:function(a){var b=a[0],c=a[1];return Math.sqrt(Math.pow(Math.abs(c.clientX-b.clientX),2)+Math.pow(Math.abs(c.clientY-b.clientY),2))},_getMiddle:function(a){var b=a[0],c=a[1];return{clientX:(c.clientX-b.clientX)/2+b.clientX,clientY:(c.clientY-b.clientY)/2+b.clientY}},_trigger:function(a){"string"==typeof a&&(a="panzoom"+a),this.$elem.triggerHandler(a,[this].concat(m.call(arguments,1)))},_startMove:function(a,d){var e,f,g,h,i,j,k,l,m=this,o=this.options,p=o.eventNamespace,q=this.getMatrix(),r=q.slice(0),s=+r[4],t=+r[5],u={matrix:q,animate:"skip"};n?(f="pointermove",g="pointerup"):"touchstart"===a.type?(f="touchmove",g="touchend"):(f="mousemove",g="mouseup"),f+=p,g+=p,this.transition(!0),this.panning=!0,this._trigger("start",a,d),d&&2===d.length?(h=this._getDistance(d),i=+q[0],j=this._getMiddle(d),e=function(a){a.preventDefault();var b=m._getMiddle(d=a.touches),c=m._getDistance(d)-h;m.zoom(c*(o.increment/100)+i,{focal:b,matrix:q,animate:!1}),m.pan(+q[4]+b.clientX-j.clientX,+q[5]+b.clientY-j.clientY,u),j=b}):(k=a.pageX,l=a.pageY,e=function(a){a.preventDefault(),m.pan(s+a.pageX-k,t+a.pageY-l,u)}),b(document).off(p).on(f,e).on(g,function(a){a.preventDefault(),b(this).off(p),m.panning=!1,a.type="panzoomend",m._trigger(a,q,!c(q,r))})}},b.Panzoom=g,b.fn.panzoom=function(a){var c,d,e,f;return"string"==typeof a?(f=[],d=m.call(arguments,1),this.each(function(){c=b.data(this,l),c?"_"!==a.charAt(0)&&"function"==typeof(e=c[a])&&void 0!==(e=e.apply(c,d))&&f.push(e):f.push(void 0)}),f.length?1===f.length?f[0]:f:this):this.each(function(){new g(this,a)})},g});;
/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Version: 3.1.12
 *
 * Requires: jQuery 1.2.2+
 */
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a:a(jQuery)}(function(a){function b(b){var g=b||window.event,h=i.call(arguments,1),j=0,l=0,m=0,n=0,o=0,p=0;if(b=a.event.fix(g),b.type="mousewheel","detail"in g&&(m=-1*g.detail),"wheelDelta"in g&&(m=g.wheelDelta),"wheelDeltaY"in g&&(m=g.wheelDeltaY),"wheelDeltaX"in g&&(l=-1*g.wheelDeltaX),"axis"in g&&g.axis===g.HORIZONTAL_AXIS&&(l=-1*m,m=0),j=0===m?l:m,"deltaY"in g&&(m=-1*g.deltaY,j=m),"deltaX"in g&&(l=g.deltaX,0===m&&(j=-1*l)),0!==m||0!==l){if(1===g.deltaMode){var q=a.data(this,"mousewheel-line-height");j*=q,m*=q,l*=q}else if(2===g.deltaMode){var r=a.data(this,"mousewheel-page-height");j*=r,m*=r,l*=r}if(n=Math.max(Math.abs(m),Math.abs(l)),(!f||f>n)&&(f=n,d(g,n)&&(f/=40)),d(g,n)&&(j/=40,l/=40,m/=40),j=Math[j>=1?"floor":"ceil"](j/f),l=Math[l>=1?"floor":"ceil"](l/f),m=Math[m>=1?"floor":"ceil"](m/f),k.settings.normalizeOffset&&this.getBoundingClientRect){var s=this.getBoundingClientRect();o=b.clientX-s.left,p=b.clientY-s.top}return b.deltaX=l,b.deltaY=m,b.deltaFactor=f,b.offsetX=o,b.offsetY=p,b.deltaMode=0,h.unshift(b,j,l,m),e&&clearTimeout(e),e=setTimeout(c,200),(a.event.dispatch||a.event.handle).apply(this,h)}}function c(){f=null}function d(a,b){return k.settings.adjustOldDeltas&&"mousewheel"===a.type&&b%120===0}var e,f,g=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],h="onwheel"in document||document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],i=Array.prototype.slice;if(a.event.fixHooks)for(var j=g.length;j;)a.event.fixHooks[g[--j]]=a.event.mouseHooks;var k=a.event.special.mousewheel={version:"3.1.12",setup:function(){if(this.addEventListener)for(var c=h.length;c;)this.addEventListener(h[--c],b,!1);else this.onmousewheel=b;a.data(this,"mousewheel-line-height",k.getLineHeight(this)),a.data(this,"mousewheel-page-height",k.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var c=h.length;c;)this.removeEventListener(h[--c],b,!1);else this.onmousewheel=null;a.removeData(this,"mousewheel-line-height"),a.removeData(this,"mousewheel-page-height")},getLineHeight:function(b){var c=a(b),d=c["offsetParent"in a.fn?"offsetParent":"parent"]();return d.length||(d=a("body")),parseInt(d.css("fontSize"),10)||parseInt(c.css("fontSize"),10)||16},getPageHeight:function(b){return a(b).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})});;
"use strict";

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

var MOUSEMOVE = "MOUSEMOVE";
var MOUSEDOWN = "MOUSEDOWN";
var MOUSEUP = "MOUSEUP";
var MOUSEOUT = "MOUSEOUT";
var ERROR = "ERROR";
var SUCCESS = "SUCCESS";
var TIMEDOUT = "TIMEDOUT";
var ROTATE = "ROTATE";
var MOVE = "MOVE";

var ImagesLoader =
/*#__PURE__*/
function () {
	function ImagesLoader(core) {
		_classCallCheck(this, ImagesLoader);

		this.core = core;
		this.count = 0;
		this.images = [];
		this.errors = [];
		this.isAllLoaded = false;
		this.isEnded = false;
		this.loadImages();
	}

	_createClass(ImagesLoader, [{
		key: "createDOM",
		value: function createDOM() {
			var $wrapper = this.core.wrapper.imagecontent;
			var $img = $wrapper.find("img");

			for (var id = 0; id < this.images.length; id++) {
				var img = this.images[id];
				var number = id + 1;
				$wrapper.append(img);
			}

			$img.remove();
		}
	}, {
		key: "loading",
		value: function loading(id, callback, timeout) {
			var _this = this;

			var _this$core$images = this.core.images,
				filesName = _this$core$images.filesName,
				src = _this$core$images.src;
			timeout = timeout || 5000;
			var timedOut = false,
				timer;
			var imgPath = src + filesName + ".jpg";
			imgPath = imgPath.replace("{$i}", id.toString());
			var img = new Image();

			img.onerror = img.onabort = function () {
				if (!timedOut) {
					clearTimeout(timer);
					callback(img, ERROR, _this);
				}
			};

			img.onload = function () {
				if (!timedOut) {
					clearTimeout(timer);
					callback(img, SUCCESS, _this);
				}
			};

			img.src = imgPath;
			img.className = "frame-" + id;

			img.ondragstart = function () {
				return false;
			};

			if (id === 1) {
			    img.style.zIndex = "1";
			} else {
			    img.style.zIndex = "0";
			}

			timer = setTimeout(function () {
				timedOut = true;
				img.src = imgPath;
				callback(img, TIMEDOUT, _this);
			}, timeout);
		}
	}, {
		key: "getstatus",
		value: function getstatus(img, stats, _this) {
			_this.count++;

			if (stats === SUCCESS) {
				_this.images.push(img);
			} else {
				_this.errors.push(img);
			}

			if (_this.count === _this.core.images.max) {
				_this.isEnded = true;
			}
		}
	}, {
		key: "loadImages",
		value: function loadImages() {
			var _this$core$images2 = this.core.images,
				min = _this$core$images2.min,
				max = _this$core$images2.max;

			for (var id = min; id <= max; id++) {
				this.loading(id, this.getstatus);
			}
		}
	}]);

	return ImagesLoader;
}();

var Module360 =
/*#__PURE__*/
function () {
	function Module360(id) {
		_classCallCheck(this, Module360);

		var $wrapper = $(id);
		this.images = {
			min: $wrapper.data("min-value"),
			max: $wrapper.data("max-value"),
			filesName: $wrapper.data("files"),
			src: $wrapper.data("src")
		};
		this.isLoaded = false;
		this.isActive = false;
		this.drag = {
			status: false,
			type: null,
			start: {
				x: 0,
				y: 0
			}
		};
		this.currentFrame = 1;
		this.mode = ROTATE;
		this.mouse = {
			x: 0,
			y: 0
		};
		this.time = {
			fps: 13,
			interval: null,
			then: Date.now(),
			delta: null,
			now: null,
            delay : 1000
		};
		this.wrapper = {
			el: $wrapper,
			imagecontent: $wrapper.find(".image-content"),
			preloader: $wrapper.find(".preloader")
		};
		this.animation = {
			isAnimating: false,
			id: null,
			timeOut: null,
            isInfinite : false,
        };
        this.isTouch = true == ("ontouchstart" in window || window.DocumentTouch && document instanceof DocumentTouch);
	}

	_createClass(Module360, [{
		key: "updateFrame",
        value: function updateFrame(dir) {
            
			var totalFrames = this.images.max;
			var $images = this.wrapper.imagecontent.find("img");
			this.currentFrame += dir;
            if (this.currentFrame < 1) this.currentFrame = totalFrames; else if (this.currentFrame > totalFrames) this.currentFrame = 1;
            if (!this.isTouch) {
                $images.css('zIndex', '0');
                $(".frame-" + this.currentFrame).css('zIndex', '1');
            } else {
                $images.hide();
                $(".frame-" + this.currentFrame).show();
            }
			
		}
	}, {
		key: "animLoop",
		value: function animLoop() {
			var _this2 = this;
			this.animation.id = window.requestAnimationFrame(function () {
				return _this2.animLoop();
			});
			this.time.now = Date.now();
			this.time.delta = this.time.now - this.time.then;
			if (this.time.delta > this.time.interval) {
				this.time.then = this.time.now - this.time.delta % this.time.interval;
				this.updateFrame(1);
			}
			if ((!this.animation.isInfinite) && (this.currentFrame == 1)) {
			    this.stop();
			}   
		}
	}, {
		key: "stop",
		value: function stop() {
			clearTimeout(this.animation.timeOut);
			if (this.animation.isAnimating === true) {
				this.animation.isAnimating = false;
				cancelAnimationFrame(this.animation.id);
			}
		}
	}, {
		key: "start",
		value: function start() {
			this.time.interval = 1000 / this.time.fps;
			if (this.animation.isAnimating === false) {
			    this.animation.isAnimating = true;
				this.animLoop();
			}
		}
	}, {
		key: "loadImages",
		value: function loadImages() {
		    var _this = this;
			var imagesLoader = new ImagesLoader(this);
			var interval = setInterval(function () {
				if (imagesLoader.isEnded) {
					
					if (imagesLoader.errors.length === 0) {
					    imagesLoader.createDOM();
                        //Rajoute un petit timeout pour éviter un flash sur chrome Mac
					    setTimeout(function () {
					        _this.wrapper.preloader.fadeOut("fast");
					        _this.isLoaded = true;
					        _this.start();
					    }, 500);
					}
					clearTimeout(interval);
				}
			}, 500);
		}
	}, {
		key: "eventsListeners",
		value: function eventsListeners() {
			var _this3 = this;

			this.wrapper.el.on("mousedown touchstart", function (event) {
				event.preventDefault();
				event.stopPropagation();

				_this3.onDown(event);

				return false;
			});
		}
	}, {
		key: "selectMode",
		value: function selectMode(event) {
			var $target = $(event.currentTarget);
			var $siblings = $target.siblings();
			$siblings.removeClass("active");
			$target.addClass("active");

			if ($target.hasClass("move")) {
				this.mode = MOVE;
			} else {
				this.mode = ROTATE;
			}
		}
	}, {
		key: "init",
		value: function init() {
		    var _this = this;
			this.currentFrame = 1;
			this.isActive = true;
			if (!this.isLoaded) {
			    this.wrapper.preloader.fadeIn("fast");
			    this.loadImages();
			} else {
			    //Rajoute un petit timeout pour laisser le temps au carousel de finir son déplacement avant de lancer
			    setTimeout(function () {
			        _this.start();
			    }, 250);
			    
			}
			 
			this.eventsListeners();
		}
	}, {
		key: "destroy",
		value: function destroy() {
			this.isActive = false;
			this.stop();
			this.reset();
			this.wrapper.el.off("mousedown touchstart");
		}
	}, {
		key: "reset",
		value: function removeDOM() {
			var $images = this.wrapper.imagecontent.find("img");            
            if (!this.isTouch) {
                $images.not($(".frame-1")).css('zIndex', '0');
                $(".frame-1").css('zIndex', '1');
            } else {
                $images.not($(".frame-1")).hide();
                $(".frame-1").show();
            }
		}
	}, 
    {
		key: "onDown",
		value: function onDown(e) {
			var _this4 = this;
           
           
			this.drag.status = true;
			this.drag.type = MOUSEDOWN;
			
            if (!_this4.isTouch) {
                this.drag.start.x = e.clientX;
                this.drag.start.y = e.clientY;
            } else {

                this.drag.start.x = e.originalEvent.touches[0].clientX;
                this.drag.start.y = e.originalEvent.touches[0].clientY;
            }
			this.stop();
			this.wrapper.el.on("mousemove touchmove", function (event) {
				event.preventDefault();
                event.stopPropagation();
                

				_this4.onMouseMove(event);

				return false;
			}).one("mouseup mouseleave touchend touchcancel", function (event) {
				event.preventDefault();
				event.stopPropagation();
				_this4.onUp(event);
				_this4.wrapper.el.off("mousemove touchmove");

				return false;
			});
		}
	}, {
		key: "onMouseMove",
		value: function onMouseMove(e) {
			
            
            if (!this.isTouch) {
				this.mouse.x = e.clientX;
				this.mouse.y = e.clientY;
			} else {
			   
			    this.mouse.x = e.originalEvent.touches[0].clientX;
			    this.mouse.y = e.originalEvent.touches[0].clientY;
			}
            
            var dx = this.mouse.x - this.drag.start.x;
            
			var abs_dx = Math.abs(dx);

            if (!this.isTouch) {
				if (abs_dx > 3) {
				    this.updateFrame(-dx / abs_dx);
				    this.drag.start.x = e.clientX;
				    this.drag.start.y = e.clientY;
				}

			} else {
				if (abs_dx > 5) {
				    this.updateFrame(-dx / abs_dx);
				    this.drag.start.x = e.originalEvent.touches[0].clientX;
				    this.drag.start.y = e.originalEvent.touches[0].clientY;
				}

			}
		}
	}, {
		key: "onUp",
		value: function onUp(e) {
			var _this5 = this;			
			clearTimeout(this.animation.timeOut);
			if (this.animation.isInfinite) {
			    this.animation.timeOut = setTimeout(function () {
			        _this5.start();
			    }, this.time.delay);
			}
			
		}
	}]);

	return Module360;
}();
;
// MSDropDown - jquery.dd.js
// author: Marghoob Suleman - http://www.marghoobsuleman.com/
// Date: 10 Nov, 2012 
// Version: 3.5.2
// Revision: 27
// web: www.marghoobsuleman.com
/*
// msDropDown is free jQuery Plugin: you can redistribute it and/or modify
// it under the terms of the either the MIT License or the Gnu General Public License (GPL) Version 2
*/ 
;eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('4 1E=1E||{};(9($){1E={3Y:{2o:\'3.5.2\'},3Z:"5D 5E",3q:20,41:9(v){6(v!==14){$(".2X").1m({1w:\'3r\',2b:\'4L\'})}1d{$(".2X").1m({1w:\'4M\',2b:\'3s\'})}},3t:\'\',3u:9(a,b,c){c=c||"42";4 d;25(c.2p()){1i"42":1i"4N":d=$(a).2o(b).1b("1V");1j}15 d}};$.3v={};$.2o={};$.2Y(11,$.3v,1E);$.2Y(11,$.2o,1E);6($.1P.1M===1B){$.1P.1M=$.1P.5F}6($.1P.18===1B){$.1P.18=$.1P.5G;$.1P.1x=$.1P.5H}6(1y $.3w.4O===\'9\'){$.3w[\':\'].43=$.3w.4O(9(b){15 9(a){15 $(a).1p().3x().3y(b.3x())>=0}})}1d{$.3w[\':\'].43=9(a,i,m){15 $(a).1p().3x().3y(m[3].3x())>=0}}9 1V(q,t){4 t=$.2Y(11,{1N:{1b:1g,1n:0,3z:1g,2c:0,1Q:14,2Z:5I},3A:\'1V\',1w:5J,1W:7,3B:0,30:11,1J:5K,26:14,3C:\'5L\',2q:\'1X\',3D:\'3r\',2d:11,1C:\'\',3E:0.7,44:11,3F:0,1u:14,3G:\'5M\',2e:\'\',2f:\'\',2g:11,1F:11,2r:11,18:{3u:1g,2G:1g,3H:1g,28:1g,1G:1g,2H:1g,2I:1g,1X:1g,45:1g,48:1g,2s:1g,2J:1g,31:1g,2t:1g,2u:1g}},t);4 u=1a;4 x={49:\'5N\',1R:\'5O\',4a:\'5P\',2h:\'5Q\',1l:\'5R\'};4 y={1V:t.3A,32:\'32\',4P:\'5S 5T\',4b:\'4b\',3I:\'3I\',2K:\'2K\',1q:\'1q\',2X:\'2X\',4Q:\'4Q\',4R:\'4R\',19:\'19\',4c:\'4c\',3J:"3J",4d:"4d",1h:"1h",33:"5U",34:\'34\',3K:\'3K\'};4 z={12:\'5V\',2v:\'2v\',4S:\'5W 4T\',3L:"3L"};4 A=14,1Y=14,1k=14,3M={},q,35={},36=14;4 B=40,4e=38,4f=37,4g=39,4U=27,4h=13,3a=47,4i=16,4j=17,4V=8,4W=46;4 C=14,2i=14,3b=1g,2L=14,3c,5X=14;4 D=3d,3e=4k.5Y.5Z,4X=3e.60(/61/i);t.2g=t.2g.2j();t.1F=t.1F.2j();4 E=9(a){15(62.4Y.2j.4Z(a)=="[50 51]")?11:14};4 F=9(){4 a=3e.3y("63");6(a>0){15 2w(3e.64(a+5,3e.3y(".",a)))}1d{15 0}};4 G=9(){t.3A=$("#"+q).1b("65")||t.3A;t.1W=$("#"+q).1b("66")||t.1W;6($("#"+q).1b("52")==14){t.30=$("#"+q).1b("52")};t.26=$("#"+q).1b("53")||t.26;t.3C=$("#"+q).1b("67")||t.3C;t.2q=$("#"+q).1b("2q")||t.2q;t.3D=$("#"+q).1b("68")||t.3D;t.2d=$("#"+q).1b("69")||t.2d;t.3E=$("#"+q).1b("6a")||t.3E;t.3F=$("#"+q).1b("54")||t.3F;t.1u=$("#"+q).1b("6b")||t.1u;t.3G=$("#"+q).1b("6c")||t.3G;t.2e=$("#"+q).1b("2e")||t.2e;t.2f=$("#"+q).1b("2f")||t.2f;t.2g=$("#"+q).1b("6d")||t.2g;t.1F=$("#"+q).1b("6e")||t.1F;t.2r=$("#"+q).1b("6f")||t.2r;t.2g=t.2g.2j();t.1F=t.1F.2j();t.2r=t.2r.2j()};4 H=9(a){6(3M[a]===1B){3M[a]=D.6g(a)}15 3M[a]};4 I=9(a){4 b=L("1l");15 $("#"+b+" 12."+z.12).1o(a)};4 J=9(){6(t.1N.1b){4 a=["1h","1D","1r"];2M{6(!q.1H){q.1H="42"+1E.3q};t.1N.1b=55(t.1N.1b);4 b="6h"+(1E.3q++);4 c={};c.1H=b;c.3z=t.1N.3z||q.1H;6(t.1N.2c>0){c.2c=t.1N.2c};c.1Q=t.1N.1Q;4 d=O("4N",c);1Z(4 i=0;i<t.1N.1b.1c;i++){4 f=t.1N.1b[i];4 g=3N 4l(f.1p,f.1f);1Z(4 p 3O f){6(p.2p()!=\'1p\'){4 h=($.6i(p.2p(),a)!=-1)?"1b-":"";g.6j(h+p,f[p])}};d.1K[i]=g};H(q.1H).1s(d);d.1n=t.1N.1n;$(d).1m({2Z:t.1N.2Z+\'2N\'});q=d}2O(e){6k"6l 6m 6n 6o 3O 6p 1b.";}}};4 K=9(){J();6(!q.1H){q.1H="6q"+(1E.3q++)};q=q.1H;u.6r=q;G();1k=H(q).2K;4 a=t.1u;6(a.2j()==="11"){H(q).1Q=11;t.1u=11};A=(H(q).2c>1||H(q).1Q==11)?11:14;6(A){1Y=H(q).1Q};56();57();1v("58",2k());1v("59",$("#"+q+" 1S:19"));4 b=L("1l");3c=$("#"+b+" 12."+y.19);6(t.2g==="11"){$("#"+q).18("2H",9(){21(1a.1n)})};H(q).4m=9(e){$("#"+q).2o().1b("1V").4m()}};4 L=9(a){15 q+x[a]};4 M=9(a){4 s=(a.1C===1B)?"":a.1C.5a;15 s};4 N=9(a){4 b=\'\',1r=\'\',1h=\'\',1f=-1,1p=\'\',1e=\'\',1z=\'\',1o;6(a!==1B){4 c=a.1r||"";6(c!=""){4 d=/^\\{.*\\}$/;4 e=d.6s(c);6(e&&t.2d){4 f=55("["+c+"]")};1r=(e&&t.2d)?f[0].1r:1r;1h=(e&&t.2d)?f[0].1h:1h;b=(e&&t.2d)?f[0].1D:c;1z=(e&&t.2d)?f[0].1z:1z;1o=a.1o};1p=a.1p||\'\';1f=a.1f||\'\';1e=a.1e||"";1r=$(a).1M("1b-1r")||$(a).1b("1r")||(1r||"");1h=$(a).1M("1b-1h")||$(a).1b("1h")||(1h||"");b=$(a).1M("1b-1D")||$(a).1b("1D")||(b||"");1z=$(a).1M("1b-1z")||$(a).1b("1z")||(1z||"");1o=$(a).1o()};4 o={1D:b,1r:1r,1h:1h,1f:1f,1p:1p,1e:1e,1z:1z,1o:1o};15 o};4 O=9(a,b,c){4 d=D.6t(a);6(b){1Z(4 i 3O b){25(i){1i"1C":d.1C.5a=b[i];1j;2P:d[i]=b[i];1j}}};6(c){d.6u=c};15 d};4 P=9(){4 a=L("49");6($("#"+a).1c==0){4 b={1C:\'1w: 4M;4n: 2x;2b: 3s;\',1e:y.2X};b.1H=a;4 c=O("2Q",b);$("#"+q).5b(c);$("#"+q).6v($("#"+a))}1d{$("#"+a).1m({1w:0,4n:\'2x\',2b:\'3s\'})};H(q).3f=-1};4 Q=9(){4 a=(t.1F=="11")?" 2R":"";4 b={1e:y.1V+" 5c"+a};4 c=M(H(q));4 w=$("#"+q).6w();b.1C="2Z: "+w+"2N;";6(c.1c>0){b.1C=b.1C+""+c};b.1H=L("1R");b.3f=H(q).3f;4 d=O("2Q",b);15 d};4 R=9(){4 a;6(H(q).1n>=0){a=H(q).1K[H(q).1n]}1d{a={1f:\'\',1p:\'\'}}4 b="",4o="";4 c=$("#"+q).1b("53");6(c){t.26=c};6(t.26!=14){b=" "+t.26;4o=" "+a.1e};4 d=(t.1F=="11")?" "+z.2v:"";4 e=O("2Q",{1e:y.32+b+d});4 f=O("2l",{1e:y.4c});4 g=O("2l",{1e:y.4P});4 h=L("4a");4 i=O("2l",{1e:y.3I+4o,1H:h});4 j=N(a);4 k=j.1D;4 l=j.1p||"";6(k!=""&&t.30){4 m=O("3P");m.4p=k;6(j.1z!=""){m.1e=j.1z+" "}};4 n=O("2l",{1e:y.33},l);e.1s(f);e.1s(g);6(m){i.1s(m)};i.1s(n);e.1s(i);4 o=O("2l",{1e:y.1h},j.1h);i.1s(o);15 e};4 S=9(){4 a=L("2h");4 b=(t.1F=="11")?"2R":"";4 c=O("2y",{1H:a,5d:\'1p\',1f:\'\',6x:\'1x\',1e:\'1p 4T \'+b,1C:\'22: 2z\'});15 c};4 T=9(a){4 b={};4 c=M(a);6(c.1c>0){b.1C=c};4 d=(a.2K)?y.2K:y.1q;d=(a.19)?(d+" "+y.19):d;d=d+" "+z.12;b.1e=d;6(t.26!=14){b.1e=d+" "+a.1e};4 e=O("12",b);4 f=N(a);6(f.1r!=""){e.1r=f.1r};4 g=f.1D;6(g!=""&&t.30){4 h=O("3P");h.4p=g;6(f.1z!=""){h.1e=f.1z+" "}};6(f.1h!=""){4 i=O("2l",{1e:y.1h},f.1h)};4 j=a.1p||"";4 k=O("2l",{1e:y.33},j);6(t.1u===11){4 l=O("2y",{5d:\'3g\',3z:q+t.3G+\'[]\',1f:a.1f||"",1e:"3g"});e.1s(l);6(t.1u===11){l.29=(a.19)?11:14}};6(h){e.1s(h)};e.1s(k);6(i){e.1s(i)}1d{6(h){h.1e=h.1e+z.3L}};4 m=O("2Q",{1e:\'6y\'});e.1s(m);15 e};4 U=9(){4 a=L("1l");4 b={1e:y.4b+" 6z "+z.4S,1H:a};6(A==14){b.1C="z-1o: "+t.1J}1d{b.1C="z-1o:1"};4 c=$("#"+q).1b("54")||t.3F;6(c){b.1C=(b.1C||"")+";2Z:"+c};4 d=O("2Q",b);4 e=O("4q");6(t.26!=14){e.1e=t.26};4 f=H(q).23;1Z(4 i=0;i<f.1c;i++){4 g=f[i];4 h;6(g.4r.2p()=="3J"){h=O("12",{1e:y.3J});4 k=O("2l",{1e:y.4d},g.33);h.1s(k);4 l=g.23;4 m=O("4q");1Z(4 j=0;j<l.1c;j++){4 n=T(l[j]);m.1s(n)};h.1s(m)}1d{h=T(g)};e.1s(h)};d.1s(e);15 d};4 V=9(a){4 b=L("1l");6(a){6(a==-1){$("#"+b).1m({1w:"3r",4n:"3r"})}1d{$("#"+b).1m("1w",a+"2N")};15 14};4 c;4 d=H(q).1K.1c;6(d>t.1W||t.1W){4 e=$("#"+b+" 12:6A");4 f=2w(e.1m("5e-6B"))+2w(e.1m("5e-2a"));6(t.3B===0){$("#"+b).1m({5f:\'2x\',22:\'3Q\'});t.3B=3h.6C(e.1w());$("#"+b).1m({5f:\'1T\'});6(!A||t.1u===11){$("#"+b).1m({22:\'2z\'})}};c=((t.3B+f)*3h.5g(t.1W,d))+3}1d 6(A){c=$("#"+q).1w()};15 c};4 W=9(){4 j=L("1l");$("#"+j).18("1X",9(e){6(1k===11)15 14;e.1U();e.2m();6(A){3R()}});$("#"+j+" 12."+y.1q).18("1X",9(e){6(e.5h.4r.2p()!=="2y"){2A(1a)}});$("#"+j+" 12."+y.1q).18("2t",9(e){6(1k===11)15 14;3c=$("#"+j+" 12."+y.19);3b=1a;e.1U();e.2m();6(t.1u===11){6(e.5h.4r.2p()==="2y"){2i=11}};6(A===11){6(1Y){6(C===11){$(1a).1t(y.19);4 a=$("#"+j+" 12."+y.19);4 b=I(1a);6(a.1c>1){4 c=$("#"+j+" 12."+z.12);4 d=I(a[0]);4 f=I(a[1]);6(b>f){d=(b);f=f+1};1Z(4 i=3h.5g(d,f);i<=3h.6D(d,f);i++){4 g=c[i];6($(g).3S(y.1q)){$(g).1t(y.19)}}}}1d 6(2i===11){$(1a).6E(y.19);6(t.1u===11){4 h=1a.4s[0];h.29=!h.29}}1d{$("#"+j+" 12."+y.19).1I(y.19);$("#"+j+" 2y:3g").1M("29",14);$(1a).1t(y.19);6(t.1u===11){1a.4s[0].29=11}}}1d{$("#"+j+" 12."+y.19).1I(y.19);$(1a).1t(y.19)}}1d{$("#"+j+" 12."+y.19).1I(y.19);$(1a).1t(y.19)}});$("#"+j+" 12."+y.1q).18("3i",9(e){6(1k===11)15 14;e.1U();e.2m();6(3b!=1g){6(1Y){$(1a).1t(y.19);6(t.1u===11){1a.4s[0].29=11}}}});$("#"+j+" 12."+y.1q).18("2s",9(e){6(1k===11)15 14;$(1a).1t(y.34)});$("#"+j+" 12."+y.1q).18("2J",9(e){6(1k===11)15 14;$("#"+j+" 12."+y.34).1I(y.34)});$("#"+j+" 12."+y.1q).18("2u",9(e){6(1k===11)15 14;e.1U();e.2m();6(t.1u===11){2i=14};4 a=$("#"+j+" 12."+y.19).1c;2L=(3c.1c!=a||a==0)?11:14;3j();3k();3R();3b=1g});6(t.44==14){$("#"+j+" 12."+z.12).18("1X",9(e){6(1k===11)15 14;2B(1a,"1X")});$("#"+j+" 12."+z.12).18("3i",9(e){6(1k===11)15 14;2B(1a,"3i")});$("#"+j+" 12."+z.12).18("2s",9(e){6(1k===11)15 14;2B(1a,"2s")});$("#"+j+" 12."+z.12).18("2J",9(e){6(1k===11)15 14;2B(1a,"2J")});$("#"+j+" 12."+z.12).18("2t",9(e){6(1k===11)15 14;2B(1a,"2t")});$("#"+j+" 12."+z.12).18("2u",9(e){6(1k===11)15 14;2B(1a,"2u")})}};4 X=9(){4 a=L("1l");$("#"+a).1x("1X");$("#"+a+" 12."+y.1q).1x("3i");$("#"+a+" 12."+y.1q).1x("1X");$("#"+a+" 12."+y.1q).1x("2s");$("#"+a+" 12."+y.1q).1x("2J");$("#"+a+" 12."+y.1q).1x("2t");$("#"+a+" 12."+y.1q).1x("2u")};4 Y=9(a,b,c){$("#"+a).1x(b,c);$("#"+a).4t(b);$("#"+a).18(b,c)};4 Z=9(){4 a=L("1R");4 b=L("2h");4 c=L("1l");$("#"+a).18(t.2q,9(e){6(1k===11)15 14;1O(t.2q);e.1U();e.2m();3T(e)});$("#"+a).18("2S",9(e){4 k=e.6F;6(!36&&(k==4h||k==4e||k==B||k==4f||k==4g||(k>=3a&&!A))){3T(e);6(k>=3a){4u()}1d{e.1U();e.6G()}}});$("#"+a).18("31",4v);$("#"+a).18("2I",4w);$("#"+b).18("2I",9(e){Y(a,"31",4v)});W();$("#"+a).18("45",5i);$("#"+a).18("48",5j);$("#"+a).18("3i",5k);$("#"+a).18("6H",5l);$("#"+a).18("2t",5m);$("#"+a).18("2u",5n)};4 4v=9(e){1O("31")};4 4w=9(e){1O("2I")};4 3U=9(){4 a=L("1R");4 b=L("1l");6(A===11&&t.1u===14){$("#"+a+" ."+y.32).3l();$("#"+b).1m({22:\'3Q\',2b:\'4L\'})}1d{6(t.1u===14){1Y=14};$("#"+a+" ."+y.32).2C();$("#"+b).1m({22:\'2z\',2b:\'3s\'});4 c=$("#"+b+" 12."+y.19)[0];$("#"+b+" 12."+y.19).1I(y.19);4 d=I($(c).1t(y.19));21(d)};V(V())};4 4x=9(){4 a=L("1R");4 b=(1k==11)?t.3E:1;6(1k===11){$("#"+a).1t(y.3K)}1d{$("#"+a).1I(y.3K)}};4 5o=9(){4 a=L("2h");6(t.2r=="11"){$("#"+a).18("2T",5p)};3U();4x()};4 57=9(){4 a=Q();4 b=R();a.1s(b);4 c=S();a.1s(c);4 d=U();a.1s(d);$("#"+q).5b(a);P();5o();Z();4 e=L("1l");6(t.2e!=\'\'){$("#"+e).2e(t.2e)};6(t.2f!=\'\'){$("#"+e).2f(t.2f)};6(1y t.18.3u=="9"){t.18.3u.24(u,1A)}};4 4y=9(b){4 c=L("1l");$("#"+c+" 12."+z.12).1I(y.19);6(t.1u===11){$("#"+c+" 12."+z.12+" 2y.3g").1M("29",14)};6(E(b)===11){1Z(4 i=0;i<b.1c;i++){4z(b[i])}}1d{4z(b)};9 4z(a){$($("#"+c+" 12."+z.12)[a]).1t(y.19);6(t.1u===11){$($("#"+c+" 12."+z.12)[a]).3m("2y.3g").1M("29","29")}}};4 4A=9(a,b){4 c=L("1l");4 d=a||$("#"+c+" 12."+y.19);1Z(4 i=0;i<d.1c;i++){4 e=(b===11)?d[i]:I(d[i]);H(q).1K[e].19="19"};21(d)};4 3j=9(){4 a=L("1l");4 b=$("#"+a+" 12."+y.19);6(1Y&&(C||2i)||2L){H(q).1n=-1};4 c;6(b.1c==0){c=-1}1d 6(b.1c>1){4A(b)}1d{c=I($("#"+a+" 12."+y.19))};6((H(q).1n!=c||2L)&&b.1c<=1){2L=14;4 e=3n("2H");H(q).1n=c;21(c);6(1y t.18.2H=="9"){4 d=2k();t.18.2H(d.1b,d.1L)};$("#"+q).4t("2H")}};4 21=9(a,b){6(a!==1B){4 c,1f,2D;6(a==-1){c=-1;1f="";2D="";2E(-1)}1d{6(1y a!="50"){4 d=H(q).1K[a];H(q).1n=a;c=a;1f=N(d);2D=(a>=0)?H(q).1K[a].1p:"";2E(1B,1f);1f=1f.1f}1d{c=(b&&b.1o)||H(q).1n;1f=(b&&b.1f)||H(q).1f;2D=(b&&b.1p)||H(q).1K[H(q).1n].1p||"";2E(c)}};1v("1n",c);1v("1f",1f);1v("2D",2D);1v("23",H(q).23);1v("58",2k());1v("59",$("#"+q+" 1S:19"))}};4 3n=9(a){4 b={2U:14,2V:14,2n:14};4 c=$("#"+q);2M{6(c.1M("18"+a)!==1g){b.2n=11;b.2U=11}}2O(e){}4 d;6(1y $.5q=="9"){d=$.5q(c[0],"4B")}1d{d=c.1b("4B")};6(d&&d[a]){b.2n=11;b.2V=11};15 b};4 3R=9(){3k();$("5r").18("1X",2A);$(3d).18("2S",4C);$(3d).18("2T",4D)};4 3k=9(){$("5r").1x("1X",2A);$(3d).1x("2S",4C);$(3d).1x("2T",4D)};4 5p=9(e){6(e.2W<3a&&e.2W!=4V&&e.2W!=4W){15 14};4 a=L("1l");4 b=L("2h");4 c=H(b).1f;6(c.1c==0){$("#"+a+" 12:2x").2C();V(V())}1d{$("#"+a+" 12").3l();4 d=$("#"+a+" 12:43(\'"+c+"\')").2C();6($("#"+a+" 12:1T").1c<=t.1W){V(-1)};6(d.1c>0&&!A||!1Y){$("#"+a+" ."+y.19).1I(y.19);$(d[0]).1t(y.19)}};6(!A){3o()}};4 4u=9(){6(t.2r=="11"){4 a=L("1R");4 b=L("2h");6($("#"+b+":2x").1c>0&&2i==14){$("#"+b+":2x").2C().6I("");Y(a,"2I",4w);H(b).31()}}};4 5s=9(){4 a=L("2h");6($("#"+a+":1T").1c>0){$("#"+a+":1T").3l();H(a).2I()}};4 4C=9(a){4 b=L("2h");4 c=L("1l");25(a.2W){1i B:1i 4g:a.1U();a.2m();5t();1j;1i 4e:1i 4f:a.1U();a.2m();5u();1j;1i 4U:1i 4h:a.1U();a.2m();2A();4 d=$("#"+c+" 12."+y.19).1c;2L=(3c.1c!=d||d==0)?11:14;3j();3k();3b=1g;1j;1i 4i:C=11;1j;1i 4j:2i=11;1j;2P:6(a.2W>=3a&&A===14){4u()};1j};6(1k===11)15 14;1O("2S")};4 4D=9(a){25(a.2W){1i 4i:C=14;1j;1i 4j:2i=14;1j};6(1k===11)15 14;1O("2T")};4 5i=9(a){6(1k===11)15 14;1O("45")};4 5j=9(a){6(1k===11)15 14;1O("48")};4 5k=9(a){6(1k===11)15 14;a.1U();1O("2s")};4 5l=9(a){6(1k===11)15 14;a.1U();1O("2J")};4 5m=9(a){6(1k===11)15 14;1O("2t")};4 5n=9(a){6(1k===11)15 14;1O("2u")};4 3V=9(a,b){4 c={2U:14,2V:14,2n:14};6($(a).1M("18"+b)!=1B){c.2n=11;c.2U=11};4 d=$(a).1b("4B");6(d&&d[b]){c.2n=11;c.2V=11};15 c};4 2B=9(a,b){6(t.44==14){4 c=H(q).1K[I(a)];6(3V(c,b).2n===11){6(3V(c,b).2U===11){c["18"+b]()};6(3V(c,b).2V===11){25(b){1i"2S":1i"2T":1j;2P:$(c).4t(b);1j}};15 14}}};4 1O=9(a){6(1y t.18[a]=="9"){t.18[a].24(1a,1A)};6(3n(a).2n===11){6(3n(a).2U===11){H(q)["18"+a]()}1d 6(3n(a).2V===11){25(a){1i"2S":1i"2T":1j;2P:$("#"+q).6J(a);1j}};15 14}};4 3W=9(a){4 b=L("1l");a=(a!==1B)?a:$("#"+b+" 12."+y.19);6(a.1c>0){4 c=2w(($(a).2b().2a));4 d=2w($("#"+b).1w());6(c>d){4 e=c+$("#"+b).3p()-(d/2);$("#"+b).5v({3p:e},5w)}}};4 5t=9(){4 b=L("1l");4 c=$("#"+b+" 12:1T."+z.12);4 d=$("#"+b+" 12:1T."+y.19);d=(d.1c==0)?c[0]:d;4 e=$("#"+b+" 12:1T."+z.12).1o(d);6((e<c.1c-1)){e=4E(e);6(e<c.1c){6(!C||!A||!1Y){$("#"+b+" ."+y.19).1I(y.19)};$(c[e]).1t(y.19);2E(e);6(A==11){3j()};3W($(c[e]))};6(!A){3o()}};9 4E(a){a=a+1;6(a>c.1c){15 a};6($(c[a]).3S(y.1q)===11){15 a};15 a=4E(a)}};4 5u=9(){4 b=L("1l");4 c=$("#"+b+" 12:1T."+y.19);4 d=$("#"+b+" 12:1T."+z.12);4 e=$("#"+b+" 12:1T."+z.12).1o(c[0]);6(e>=0){e=4F(e);6(e>=0){6(!C||!A||!1Y){$("#"+b+" ."+y.19).1I(y.19)};$(d[e]).1t(y.19);2E(e);6(A==11){3j()};6(2w(($(d[e]).2b().2a+$(d[e]).1w()))<=0){4 f=($("#"+b).3p()-$("#"+b).1w())-$(d[e]).1w();$("#"+b).5v({3p:f},5w)}};6(!A){3o()}};9 4F(a){a=a-1;6(a<0){15 a};6($(d[a]).3S(y.1q)===11){15 a};15 a=4F(a)}};4 3o=9(){4 a=L("1R");4 b=L("1l");4 c=$("#"+a).5x();4 d=$("#"+a).1w();4 e=$(4k).1w();4 f=$(4k).3p();4 g=$("#"+b).1w();4 h=$("#"+a).1w();4 i=t.3D.2p();6(((e+f)<3h.6K(g+d+c.2a)||i==\'6L\')&&i!=\'6M\'){h=g;$("#"+b).1m({2a:"-"+h+"2N",22:\'3Q\',1J:t.1J});6(t.1F=="11"){$("#"+a).1I("2R 2v").1t("3X")};4 h=$("#"+b).5x().2a;6(h<-10){$("#"+b).1m({2a:(2w($("#"+b).1m("2a"))-h+20+f)+"2N",1J:t.1J});6(t.1F=="11"){$("#"+a).1I("3X 2v").1t("2R")}}}1d{$("#"+b).1m({2a:h+"2N",1J:t.1J});6(t.1F=="11"){$("#"+a).1I("2R 3X").1t("2v")}};6(4X){6(F()<=7){$(\'2Q.5c\').1m("1J",t.1J-10);$("#"+a).1m("1J",t.1J+5)}}};4 3T=9(e){6(1k===11)15 14;4 a=L("1R");4 b=L("1l");6(!36){36=11;6(1E.3t!=\'\'){$("#"+1E.3t).1m({22:"2z"})};1E.3t=b;$("#"+b+" 12:2x").2C();3o();4 c=t.3C;6(c==""||c=="2z"){$("#"+b).1m({22:"3Q"});3W();6(1y t.18.2G=="9"){4 d=2k();t.18.2G(d.1b,d.1L)}}1d{$("#"+b)[c]("6N",9(){3W();6(1y t.18.2G=="9"){4 d=2k();t.18.2G(d.1b,d.1L)}})};3R()}1d{6(t.2q!==\'2s\'){2A()}}};4 2A=9(e){36=14;4 a=L("1R");4 b=L("1l");6(A===14||t.1u===11){$("#"+b).1m({22:"2z"});6(t.1F=="11"){$("#"+a).1I("2v 3X").1t("2R")}};3k();6(1y t.18.3H=="9"){4 d=2k();t.18.3H(d.1b,d.1L)};5s();V(V());$("#"+b).1m({1J:1});2E(H(q).1n)};4 56=9(){2M{35=$.2Y(11,{},H(q));1Z(4 i 3O 35){6(1y 35[i]!="9"){u[i]=35[i]}}}2O(e){};u.2D=(H(q).1n>=0)?H(q).1K[H(q).1n].1p:"";u.3Y=1E.3Y.2o;u.3Z=1E.3Z};4 4G=9(a){6(a!=1g&&1y a!="1B"){4 b=L("1l");4 c=N(a);4 d=$("#"+b+" 12."+z.12+":4H("+(a.1o)+")");15{1b:c,1L:d,1S:a,1o:a.1o}};15 1g};4 2k=9(){4 a=L("1l");4 b=H(q);4 c,1L,1S,1o;6(b.1n==-1){c=1g;1L=1g;1S=1g;1o=-1}1d{1L=$("#"+a+" 12."+y.19);6(1L.1c>1){4 d=[],4I=[],6O=[];1Z(4 i=0;i<1L.1c;i++){4 e=I(1L[i]);d.5y(e);4I.5y(b.1K[e])};c=d;1S=4I;1o=d}1d{1S=b.1K[b.1n];c=N(1S);1o=b.1n}};15{1b:c,1L:1L,1o:1o,1S:1S}};4 2E=9(a,b){4 c=L("4a");4 d={};6(a==-1){d.1p="&6P;";d.1e="";d.1h="";d.1D=""}1d 6(1y a!="1B"){4 e=H(q).1K[a];d=N(e)}1d{d=b};$("#"+c).3m("."+y.33).4J(d.1p);H(c).1e=y.3I+" "+d.1e;6(d.1h!=""){$("#"+c).3m("."+y.1h).4J(d.1h).2C()}1d{$("#"+c).3m("."+y.1h).4J("").3l()};4 f=$("#"+c).3m("3P");6(f.1c>0){$(f).1G()};6(d.1D!=""&&t.30){f=O("3P",{4p:d.1D});$("#"+c).2f(f);6(d.1z!=""){f.1e=d.1z+" "};6(d.1h==""){f.1e=f.1e+z.3L}}};4 1v=9(p,v){u[p]=v};4 4K=9(a,b,i){4 c=L("1l");4 d=14;25(a){1i"28":4 e=T(b||H(q).1K[i]);4 f;6(1A.1c==3){f=i}1d{f=$("#"+c+" 12."+z.12).1c-1};6(f<0||!f){$("#"+c+" 4q").2e(e)}1d{4 g=$("#"+c+" 12."+z.12)[f];$(g).6Q(e)};X();W();6(t.18.28!=1g){t.18.28.24(1a,1A)};1j;1i"1G":d=$($("#"+c+" 12."+z.12)[i]).3S(y.19);$("#"+c+" 12."+z.12+":4H("+i+")").1G();4 h=$("#"+c+" 12."+y.1q);6(d==11){6(h.1c>0){$(h[0]).1t(y.19);4 j=$("#"+c+" 12."+z.12).1o(h[0]);21(j)}};6(h.1c==0){21(-1)};6($("#"+c+" 12."+z.12).1c<t.1W&&!A){V(-1)};6(t.18.1G!=1g){t.18.1G.24(1a,1A)};1j}};1a.6R=9(){4 a=1A[0];51.4Y.6S.4Z(1A);25(a){1i"28":u.28.24(1a,1A);1j;1i"1G":u.1G.24(1a,1A);1j;2P:2M{H(q)[a].24(H(q),1A)}2O(e){};1j}};1a.28=9(){4 a,1f,1r,1D,1h;4 b=1A[0];6(1y b=="6T"){a=b;1f=a;2F=3N 4l(a,1f)}1d{a=b.1p||\'\';1f=b.1f||a;1r=b.1r||\'\';1D=b.1D||\'\';1h=b.1h||\'\';2F=3N 4l(a,1f);$(2F).1b("1h",1h);$(2F).1b("1D",1D);$(2F).1b("1r",1r)};1A[0]=2F;H(q).28.24(H(q),1A);1v("23",H(q)["23"]);1v("1c",H(q).1c);4K("28",2F,1A[1])};1a.1G=9(i){H(q).1G(i);1v("23",H(q)["23"]);1v("1c",H(q).1c);4K("1G",1B,i)};1a.5z=9(a,b){6(1y a=="1B"||1y b=="1B")15 14;a=a.2j();2M{1v(a,b)}2O(e){};25(a){1i"2c":H(q)[a]=b;6(b==0){H(q).1Q=14};A=(H(q).2c>1||H(q).1Q==11)?11:14;3U();1j;1i"1Q":H(q)[a]=b;A=(H(q).2c>1||H(q).1Q==11)?11:14;1Y=H(q).1Q;3U();1v(a,b);1j;1i"2K":H(q)[a]=b;1k=b;4x();1j;1i"1n":1i"1f":6(a=="1n"&&E(b)===11){$("#"+q+" 1S").1M("19",14);4A(b,11);4y(b)}1d{H(q)[a]=b;4y(H(q).1n);21(H(q).1n)};1j;1i"1c":4 c=L("1l");6(b<H(q).1c){H(q)[a]=b;6(b==0){$("#"+c+" 12."+z.12).1G();21(-1)}1d{$("#"+c+" 12."+z.12+":6U("+(b-1)+")").1G();6($("#"+c+" 12."+y.19).1c==0){$("#"+c+" 12."+y.1q+":4H(0)").1t(y.19)}};1v(a,b);1v("23",H(q)["23"])};1j;1i"1H":1j;2P:2M{H(q)[a]=b;1v(a,b)}2O(e){};1j}};1a.6V=9(a){15 u[a]||H(q)[a]};1a.1T=9(a){4 b=L("1R");6(a===11){$("#"+b).2C()}1d 6(a===14){$("#"+b).3l()}1d{15($("#"+b).1m("22")=="2z")?14:11}};1a.41=9(v){1E.41(v)};1a.3H=9(){2A()};1a.2G=9(){3T()};1a.5A=9(r){6(1y r=="1B"||r==0){15 14};t.1W=r;V(V())};1a.1W=1a.5A;1a.18=9(a,b){$("#"+q).18(a,b)};1a.1x=9(a,b){$("#"+q).1x(a,b)};1a.6W=1a.18;1a.6X=9(){15 2k()};1a.5B=9(){4 a=H(q).5B.24(H(q),1A);15 4G(a)};1a.5C=9(){4 a=H(q).5C.24(H(q),1A);15 4G(a)};1a.6Y=9(a){1a.5z("1f",a)};1a.6Z=9(){4 a=L("49");4 b=L("1R");$("#"+b+", #"+b+" *").1x();H(q).3f=H(b).3f;$("#"+b).1G();$("#"+q).70().71($("#"+q));$("#"+q).1b("1V",1g)};1a.4m=9(){21(H(q).1n)};K()};$.1P.2Y({3v:9(b){15 1a.72(9(){6(!$(1a).1b(\'1V\')){4 a=3N 1V(1a,b);$(1a).1b(\'1V\',a)}})}});$.1P.2o=$.1P.3v})(73);',62,438,'||||var||if|||function||||||||||||||||||||||||||||||||||||||||||||||||||||||true|li||false|return|||on|selected|this|data|length|else|className|value|null|description|case|break|isDisabled|postChildID|css|selectedIndex|index|text|enabled|title|appendChild|addClass|enableCheckbox|cy|height|off|typeof|imagecss|arguments|undefined|style|image|msBeautify|roundedCorner|remove|id|removeClass|zIndex|options|ui|prop|byJson|cn|fn|multiple|postID|option|visible|preventDefault|dd|visibleRows|click|isMultiple|for||bW|display|children|apply|switch|useSprite||add|checked|top|position|size|jsonTitle|append|prepend|reverseMode|postTitleTextID|controlHolded|toString|cw|span|stopPropagation|hasEvent|msDropdown|toLowerCase|event|enableAutoFilter|mouseover|mousedown|mouseup|borderRadiusTp|parseInt|hidden|input|none|ct|cm|show|selectedText|cx|opt|open|change|blur|mouseout|disabled|forcedTrigger|try|px|catch|default|div|borderRadius|keydown|keyup|byElement|byJQuery|keyCode|ddOutOfVision|extend|width|showIcon|focus|ddTitle|label|hover|orginial|isOpen||||ALPHABETS_START|lastTarget|oldSelected|document|ua|tabIndex|checkbox|Math|mouseenter|bV|bZ|hide|find|bX|cr|scrollTop|counter|auto|absolute|oldDiv|create|msDropDown|expr|toUpperCase|indexOf|name|mainCSS|rowHeight|animStyle|openDirection|disabledOpacity|childWidth|checkboxNameSuffix|close|ddTitleText|optgroup|disabledAll|fnone|cacheElement|new|in|img|block|bY|hasClass|cs|bP|cl|co|borderRadiusBtm|version|author||debug|dropdown|Contains|disabledOptionEvents|dblclick|||mousemove|postElementHolder|postTitleID|ddChild|divider|optgroupTitle|UP_ARROW|LEFT_ARROW|RIGHT_ARROW|ENTER|SHIFT|CONTROL|window|Option|refresh|overflow|selectedClass|src|ul|nodeName|childNodes|trigger|cb|bN|bO|bQ|bT|updateNow|bU|events|cd|ce|getNext|getPrev|cv|eq|op|html|cz|relative|0px|select|createPseudo|arrow|borderTop|noBorderTop|ddChildMore|shadow|ESCAPE|BACKSPACE|DELETE|isIE|prototype|call|object|Array|showicon|usesprite|childwidth|eval|cu|bS|uiData|selectedOptions|cssText|after|ddcommon|type|padding|visibility|min|target|cf|cg|ch|ci|cj|ck|bR|ca|_data|body|cc|cp|cq|animate|500|offset|push|set|showRows|namedItem|item|Marghoob|Suleman|attr|bind|unbind|250|120|9999|slideDown|_mscheck|_msddHolder|_msdd|_title|_titleText|_child|ddArrow|arrowoff|ddlabel|_msddli_|border|isCreated|navigator|userAgent|match|msie|Object|MSIE|substring|maincss|visiblerows|animstyle|opendirection|jsontitle|disabledopacity|enablecheckbox|checkboxnamesuffix|reversemode|roundedcorner|enableautofilter|getElementById|msdropdown|inArray|setAttribute|throw|There|is|an|error|json|msdrpdd|element|test|createElement|innerHTML|appendTo|outerWidth|autocomplete|clear|ddchild_|first|bottom|ceil|max|toggleClass|which|stopImmediatePropagation|mouseleave|val|triggerHandler|floor|alwaysup|alwaysdown|fast|ind|nbsp|before|act|shift|string|gt|get|addMyEvent|getData|setIndexByValue|destroy|parent|replaceWith|each|jQuery'.split('|'),0,{}));;
; (function ($, window, document, undefined) {
    'use strict';
    // nom de librairie à modifier
    Foundation.libs.product = {
        name: 'product',

        version: '1.0.0',

        settings: {
            callback: function () { }
        },
        module360: {},
        sliderImagesElm: {},
        sliderImages: {},
        sliderNavigationElm: {},
        sliderNavigation: {},
        sliderImagesZoomElm: {},
        sliderImagesZoomnavigationElm: {},
        sliderImagesZoom: {},
        sliderImagesZoomnavigation: {},
        sliderOtherProducts: {},
        sliderImagesOpt: {
            loop: false,
            nav: true,
            items: 1,
            lazyLoad: true,
            dots: true,

            stagePadding: 0,
            //navContainer: '#navigationMobile',
            dotsContainer: '#wrapper-dots',
            navText: ['<img src="/images/fiche_produit/v2/fleche-gauche.svg" width="40" height="100" class="show-for-small-only" />', '<img src="/images/fiche_produit/v2/fleche-droite.svg" width="40" height="100" class="show-for-small-only" />']
        },
        sliderNavigationOpt: {
            loop: false,
            nav: true,
            items: 5,
            lazyLoad: true,
            dots: false,
            stagePadding: 0,
            navText: ['<img src="/images/fiche_produit/v2/fleche-gauche.svg" width="40" height="100" class="show-for-small-only" />', '<img src="/images/fiche_produit/v2/fleche-droite.svg" width="40" height="100" class="show-for-small-only" />']
        },
        sliderImagesZoomOpt: {
            loop: true,
            nav: false,
            navText: ['', ''],
            items: 1,
            lazyLoad: true,
            dots: false,
            stagePadding: 0
        },
        sliderImagesZoomNavigationOpt: {
            loop: false,
            nav: true,
            navText: ['<img src="/images/fiche_produit/v2/fleche-gauche.svg" width="40" height="100" />', '<img src="/images/fiche_produit/v2/fleche-droite.svg" width="40" height="100" />'],
            items: 3,
            lazyLoad: true,
            dots: false,
            stagePadding: 0,
            responsive: {
                0: {
                    items: 3
                },
                641: {
                    items: 4,
                    nav: true
                }
            }
        },
        sliderOtherProductsOpt: {
            loop: true,
            nav: true,
            items: 3,
            lazyLoad: true,
            dots: false,
            stagePadding: 0,
            navText: ['', ''],
            responsive: {
                0: {
                    items: 2
                },
                641: {
                    items: 2
                },
                961: {
                    items: 3
                }
            }
        },
        productReveal: {},
        init: function (scope, method, options) {
            // initialisation à conserver
            Foundation.inherit(this, '');
            var self = this;

            // votre code ici
            /* // exemple
            if (self.S("#" + this.settings.id).length === 0)
                self.S("#main-content", this.scope).append("<span id='" + this.settings.id + "'></span>");
            */
            this.productReveal;
            this.sliderImagesElm = $("#owl-product-slider");
            this.sliderNavigationElm = $("#owl-navigation-slider");
            this.sliderOtherProducts = $("#slider-related-products, #slider-complementary-products, #slider-musthave-products, #slider-lastvisited-products");

            $(".o-products .owl-carousel").each(function (index, item) {
                var responsive = {
                        600: {
                            items: 2,
                            loop: ($(item).find('.item').length > 2),
                            mouseDrag: ($(item).find('.item').length > 2),
                            touchDrag: ($(item).find('.item').length > 2),
                            margin: 10,
                            stagePadding: 40,
                            dots: false,
                            nav: false,
                        },
                        1020: {
                            items: 2,
                            loop: ($(item).find('.item').length > 3),
                            mouseDrag: ($(item).find('.item').length > 3),
                            touchDrag: ($(item).find('.item').length > 3),
                            dots: false,
                            nav: false,
                        }, 
                        1200: {
                            items: 4,
                            loop: ($(item).find('.item').length > 4),
                            mouseDrag: ($(item).find('.item').length > 4),
                            touchDrag: ($(item).find('.item').length > 4),
                            stagePadding: 0,
                            margin: 10,
                        }
                    };

                $(item).owlCarousel({
                    items: 1,
                    stagePadding: 30,
                    loop: true,
                    margin: 10,
                    nav: true,
                    navText: ['4', '5'],
                    dots: true,
                    mouseDrag: true,
                    touchDrag: true,
                    responsive: responsive
                });

            });
            // à conserver
            this.bindings(method, options);
        },
        initFormulaire: function () {
            try {
                $("#crosssell-add, .option").msDropdown({ roundedBorder: false });
                $(".duos, .parure").msDropdown({ roundedBorder: false, rowHeight: 40 });
                //$(".crosssell-quantity").msDropdown({ mainCSS: 'dd2' });
            } catch (e) {
                alert(e.message);
            }

        },
        initSliderImages: function () {
            var _this = this;
            //alert('init : ' + this.sliderImagesElm);
            this.sliderImages = this.sliderImagesElm.owlCarousel(this.sliderImagesOpt);
            this.sliderNavigation = this.sliderNavigationElm.owlCarousel(this.sliderNavigationOpt);

            this.sliderImages.on('changed.owl.carousel', function (e) {
                var current = e.item.index;

                var $elem = $(e.target).find(".owl-item").eq(current).find(".item");
                if ($elem.attr("id") === "module-360") {
                    _this.module360.init();
                } else {
                    if (_this.module360.isActive) {
                        _this.module360.destroy();
                    }
                }
            });

            this.sliderNavigation.on('changed.owl.carousel', function (e) {
                var current = e.item.index;
                //var src = $(e.target).find(".owl-item").eq(current).find("img").attr('src');
                //console.log('Image current is ' + src);

                $(".card").removeClass('card-selected');
                // $(e.target).find('[data-id-view=' + e.item.index + ']').addClass('card-selected');

                $(e.target).find(".owl-item").eq(current).find(".card").addClass('card-selected');
            });
        },
        initModule360: function () {

            this.module360 = new Module360("#module-360");
        },
        initSliderOtherProducts: function () {

            // On n'affiche pas la nav si moins d'éléments à afficher que nécessaire
            this.sliderOtherProducts.on('initialized.owl.carousel resized.owl.carousel', function (e) {
                $(e.target).toggleClass('hide-nav', e.item.count <= e.page.size);
            });

            this.sliderOtherProducts.owlCarousel(this.sliderOtherProductsOpt);
            Foundation.libs.common.initTrackMerch();
        },
        previewEngraving: function (obj) {
            var template = obj.template;
            var context = $("#add-product-to-cart-form");

            var rfpdt = context.find("#ReferenceProduit")[0].value;
            var codeVue = context.find("#CodeVue")[0].value;
            var codePolice = context.find("#CodePolice")[0].value;
            var codeModeGravure = context.find("#CodeModeGravure")[0].value;

            var taille = context.find("#Taille")[0].value;
            var idTemplate = template;
            var formContext = $("#preview-gravure-edit-form-" + idTemplate);

            var data = "";
            var saisie = formContext.find(".gravure-content");
            saisie.each(function (index) {
                if (data != "")
                    data += ",";
                data += "\"" + $(this).attr("name").replace("tpl" + idTemplate + "_ligne", "") + "\": \"" + $(this).val() + "\"";
            });
            data = encodeURIComponent("{" + data + "}");

            var resultatPreview = false;
            imagesCarousel = this.sliderImages;
            var slides = $("#owl-product-slider .owl-item:not(.cloned) .item");
            var slidePreview = $("#owl-product-slider .owl-item .preview-gravure");

            var indexSlide = 0;

            slides.each(function (index) {
                if ($(this).hasClass("preview-gravure")) {
                    indexSlide = index;
                }
            });


            var urlsvg = "/FullEngravingPreview.axd?rfpdt=" + rfpdt + "&codevue=" + codeVue + "&taille=" + taille + "&codemodegravure=" + codeModeGravure + "&codepolice=" + codePolice + "&template=" + idTemplate + "&data=" + data;

            var img = slidePreview.find("img");

            slidePreview.fadeOut("fast", function (e) {
                $.get(urlsvg, function (svg) {
                    // Affichage de la preview

                    $(".dataurl").val(encodeURIComponent(svg));

                    if (Modernizr.smil)    // Browser non IE
                    {
                        slidePreview.empty().append(svg).fadeIn();
                    }
                    else {   // Browser IE

                        var newImg = $('<img src="' + urlsvg + '" alt="" />');
                        slidePreview.empty().append(newImg).fadeIn();

                    }

                    // Enregistrement des données
                    $(".selectedTemplate").val(idTemplate);
                    $.ajax({
                        cache: false,
                        async: true,
                        type: "POST",
                        data: $("#add-product-to-cart-form").serialize(),
                        url: "/ProductAction/UpdatePreviewGravureForm",
                        success: function (response) {
                            imagesCarousel.trigger('to.owl.carousel', [indexSlide, 300]);
                        },
                        error: function (response) {
                            //alert("oups, impossible de vous montrer le rendu de votre bijou.");
                        }
                    });
                }, 'text');

            });
            return resultatPreview;
        },
        events: function () {
            var self = this;
            var S = this.S;
            //////////////////////////////////////////////////////////////
            //                          ETAPE1                          //
            //////////////////////////////////////////////////////////////
            $(this.scope)
                .ready(function (event) {
                    //tres important pour eviter le cache pour les requetes JSON
                    $.ajaxSetup({ cache: false });
                    if ($("#module-360")) {
                        $(document).foundation('product', 'initModule360');
                    }
                    $(document).foundation('product', 'initFormulaire');
                    $(document).foundation('product', 'initSliderImages');
                    $(document).foundation('product', 'initSliderOtherProducts');
                    //alert('coucou');



                    var $erreur = $('#displayerreur');
                    if ($erreur.length) {
                        $('#erreur-globale .error-text').html($erreur.val());
                        $('#erreur-globale').foundation('reveal', 'open');
                    }
                    var $message = $('#displaymessage');
                    if ($message.length) {
                        $('#popin_infos #content-text').html($message.val());
                        $('#popin_infos').foundation('reveal', 'open');
                    }
                })
                // AJOUT AU PANIER
                .on('submit', '#add-product-to-cart-form', function (e) {
                    var self = this;
                    e.preventDefault();
                    $('#add-to-cart-button').attr('disabled', 'disabled');

                    $.ajax(
                        {
                            cache: false,
                            async: true,
                            type: "POST",
                            url: $(this).attr('action'),
                            data: $(this).serialize(),
                            success: function (data) {
                                if (data.Success) {
                                    $('#add-to-cart-button').removeAttr('disabled');

                                    var opt = {};
                                    if (!data.HasEngraving) {
                                        opt = {
                                            product_engraving: '0',
                                            product_size: data.ProductSize,
                                        }
                                    }
                                    else {
                                        opt = {
                                            product_engraving: '1',
                                            product_size: data.ProductSize,
                                        }
                                    }

                                    $(document).foundation('mastertag', 'track_tc_event',
                                        {
                                            obj: this,
                                            trigger: 'add_to_cart_confirmed',
                                            options: opt
                                        });

                                    $(document).foundation('common', 'trackGAEvent', { category: 'produit', action: 'ajout au panier', label: tc_vars['product_id'] });

                                    if (typeof data.UrlToRedirect !== "undefined") {
                                        window.location = data.UrlToRedirect;
                                    }
                                    else {
                                        $('#product-informations').html(data._ProductInformations);

                                        // Feedback en affichant le survol du panier si on n'est pas sur mobile
                                        Foundation.libs.common.clearLightCart();

                                        // MAJ du datalayer
                                        $(document).foundation('common', 'refreshMasterTagData', data._MasterTagJson);
                                        $(document).foundation('common', 'refreshMasterTag');

                                        // Affichage de la modale d'ajout au panier
                                        var ref = $('#ReferenceProduit').attr('value');

                                        $.ajax({
                                            url: '/Product/AddToCartModal',
                                            data: { reference: ref },
                                            success: function (result) {
                                                if (result.IsValid) {
                                                    $('#ajout-produit-panier').html(result._AddProductModal)
                                                    $('#addProductReveal').foundation('reveal', 'open')
                                                    this.productReveal = new ProductReveal();
                                                }
                                                Foundation.libs.common.hidePreloader();
                                            },
                                            beforeSend: function () {
                                                Foundation.libs.common.showPreloader();
                                            }
                                        }).fail(function (e) {
                                            Foundation.libs.common.hidePreloader();
                                        });
                                    }
                                }
                                else {
                                    $('#erreur-globale .error-text').html(data.Message);
                                    $('#erreur-globale').foundation('reveal', 'open');
                                    $('#add-to-cart-button').removeAttr('disabled');
                                    Foundation.libs.common.hidePreloader();
                                }

                                $('#add-to-cart-button').removeAttr('disabled');

                            },
                            beforeSend: function () {
                                $('#preloader').show()
                                Foundation.libs.common.showPreloader();
                            },
                            complete: function () {
                                $('#add-to-cart-button').removeAttr('disabled');
                                //$('#preloader').hide();
                            }
                        }).fail(function (e) {
                            Foundation.libs.common.hidePreloader();
                        });

                    return false;
                })
                //CLOSING MODAL FOR BUTTON
                .on('click', '.close-reveal-modal-product-reveal', function (event) {
                    $('#addProductReveal').foundation('reveal', 'close')
                })
                // CHOIX DANS LISTE OPTIONS
                .on('change', '.option', function (event) {
                    $.ajax({
                        cache: false,
                        async: true,
                        type: "POST",
                        url: "/ProductAction/RechercheProduitAssocieParOption",
                        data: $(this).parents("form").serialize(),
                        success: function (data) {
                            if (data.IsValid) {
                                $("#error-options").hide();
                                window.location = data.UrlToRedirect;
                            }
                            else {
                                $("#error-options").html(data.Message);
                                $("#error-options").show();
                            }
                        },
                        beforeSend: function () {
                            $(document).foundation('common', 'showPreloader');
                        },
                        complete: function () {
                            //$(document).foundation('common', 'hidePreloader');
                        },
                        fail: function (result) {
                            Foundation.libs.common.hidePreloader();
                        }
                    });
                })
                .on('change', '.duos, .parure', function (event) {
                    window.location = $(this).val();
                })
                // CROSS SELL
                .on('change', '.crosssell-add', function (event) {
                    var referenceFormateeMaitre = $("#ReferenceFormatee").val();
                    $.ajax(
                        {
                            cache: false,
                            async: true,
                            type: "POST",
                            url: "/product/AddCrossSellProduct",
                            data: {
                                referenceFormateeMaitre: referenceFormateeMaitre,
                                referenceFormateeCrossSell: $(this).val()
                            },
                            success: function (data) {
                                $("#cross-sell-products").html(data.Products);
                                $("#product-price").html(data.Price);
                                $("#payment-terms").html(data.PaymentTerms);
                                $("#add-to-cart").html(data.AddToCart);
                                $(document).foundation('product', 'initFormulaire');
                            },
                            beforeSend: function () {
                                $(document).foundation('common', 'showPreloader');
                            },
                            complete: function () {
                                $(document).foundation('common', 'hidePreloader');
                            }
                        });
                })
                .on('change', '.crosssell-quantity', function (event) {
                    var referenceFormateeMaitre = $("#ReferenceFormatee").val();
                    $.ajax(
                        {
                            cache: false,
                            async: true,
                            type: "POST",
                            url: "/product/ChangeQuantityCrossSellProduct",
                            data: {
                                referenceFormateeMaitre: referenceFormateeMaitre,
                                referenceFormateeCrossSell: $(this).attr('data-crosssell-reference'), quantite: $(this).val()
                            },
                            success: function (data) {
                                $("#cross-sell-products").html(data.Products);
                                $("#product-price").html(data.Price);
                                $("#payment-terms").html(data.PaymentTerms);
                                $("#add-to-cart").html(data.AddToCart);
                                $(document).foundation('product', 'initFormulaire');
                            },
                            beforeSend: function () {
                                $(document).foundation('common', 'showPreloader');
                            },
                            complete: function () {
                                $(document).foundation('common', 'hidePreloader');
                            }
                        });
                })
                .on('click', '.crosssell-remove', function (event) {
                    event.preventDefault();
                    var referenceFormateeMaitre = $("#ReferenceFormatee").val();
                    $.ajax(
                        {
                            cache: false,
                            async: true,
                            type: "POST",
                            url: "/product/RemoveCrossSellProduct/",
                            data: {
                                referenceFormateeMaitre: referenceFormateeMaitre,
                                referenceFormateeCrossSell: $(this).attr('data-crosssell-reference')
                            },
                            success: function (data) {
                                $("#cross-sell-products").html(data.Products);
                                $("#product-price").html(data.Price);
                                $("#payment-terms").html(data.PaymentTerms);
                                $("#add-to-cart").html(data.AddToCart);
                                $(document).foundation('product', 'initFormulaire');
                            },
                            beforeSend: function () {
                                $(document).foundation('common', 'showPreloader');
                            },
                            complete: function () {
                                $(document).foundation('common', 'hidePreloader');
                            }
                        });
                })
                // CARROUSEL VUES PRODUIT
                // -- CLIC VIGNETTES
                .on('click', '#navigation .card', function (event) {
                    event.preventDefault();
                    $(document).foundation('product', 'carouselViewsTo', $(this).attr('data-id-view'));
                })

                .on('click', '#owl-product-slider-zoom-navigation .card', function (event) {
                    event.preventDefault();
                    $(document).foundation('product', 'carouselZoomViewsTo', $(this).attr('data-id-view'));
                })

                // -- CLIC NAVITAGION NEXT
                .on('click', '#navigation .next', function (event) {
                    event.preventDefault();
                    $(document).foundation('product', 'carouselViewsNext', $(this).attr('data-id-view'));
                })
                // -- CLIC NAVITAGION PREV
                .on('click', '#navigation .prev', function (event) {
                    event.preventDefault();
                    $(document).foundation('product', 'carouselViewsPrev', $(this).attr('data-id-view'));
                })
                // ZOOM VUES PRODUIT
                // -- CLIC IMAGES
                .on('click', '.full-screen-zoom', function (event) {
                    event.preventDefault();
                    $(document).foundation('product', 'initCarouselZoom', $(this).attr('data-active-slide'));
                })
                // CHOIX VARIANTE - DESKTOP
                .on("click", ".bt-variant-choice", function (e) {
                    var product = $(this).attr('data-product-reference');
                    var variant = $(this).attr('data-variant');
                    var tooltip = $("#" + $(this).attr('data-selector'));
                    $.ajax({
                        url: '/ProductAction/SetVariante',
                        data: {
                            reference: product,
                            variante: variant
                        },
                        success: function (html) {
                            $("#product-informations-wrapper").html(html);
                        },
                        beforeSend: function () {
                            $(document).foundation('common', 'showPreloader');
                            tooltip.remove();
                        },
                        complete: function () {
                            $(document).foundation('common', 'hidePreloader');
                            $(".tooltip").remove();
                            $(document).foundation('tooltip', 'reflow');

                            // Récréation de la liste avec les options, affiner si une liste qui n'a rien a voir est affecté par cette ligne de code
                            msBeautify.create('select');
                        },
                        cache: false
                    });
                })
                // CHOIX VARIANTE - MOBILE
                .on('change', ".dd-variante-dropdown", function (e) {
                    var product = $(this).attr('data-id');
                    var variant = $(this).val();
                    $.ajax({
                        url: '/ProductAction/SetVariante',
                        data: {
                            reference: product,
                            variante: variant
                        },
                        success: function (html) {
                            //$("#availability-wrapper").html(html);
                            $("#product-informations-wrapper").html(html);
                        },
                        beforeSend: function () {
                            $(document).foundation('common', 'showPreloader');
                        },
                        complete: function () {
                            $(document).foundation('common', 'hidePreloader');
                        },
                        cache: false
                    });
                })
                // E RESERVATION
                .on('click', '#show-clickandcollect', function (e) {
                    var popinClickAndCollect = $("#retrait-bijouterie-wrapper");
                    var gravuresCheck = $(".checkbox-gravure-inline:checked");

                    if (gravuresCheck !== undefined && gravuresCheck.length > 0) {
                        // Si au moins une gravure de prédéfinie, on affiche un message d'avertissement
                        popinClickAndCollect = $("#ajax-modal-medium");
                    }

                    var reference = $(this).attr('data-product-reference');

                    // Ouverture Popin
                    $.ajax(
                        {
                            cache: false,
                            async: true,
                            type: "GET",
                            url: '/Product/ShowClickNCollect/',
                            data: { reference: reference },
                            success: function (data) {
                                popinClickAndCollect.html(data).foundation('reveal', 'open');
                            },
                            beforeSend: function () {
                                $('#preloader').show()
                            },
                            complete: function () {
                                $('#preloader').hide();
                            }
                        });

                    const event = {
                        obj: "",
                        trigger: "e_reservation",
                        options: {
                            category: "demande e-reservation",
                            action: tc_vars.product_category,
                            label: tc_vars.product_name + "-" + tc_vars.product_id,
                            value: tc_vars.product_unitprice_ati,
                            product_brand: tc_vars.product_trademark,
                            product_cat1: tc_vars.product_cat1,
                            product_cat2: tc_vars.product_cat2,
                            product_cat3: tc_vars.product_cat3,
                            product_category: tc_vars.product_category,
                            product_currency: tc_vars.product_currency,
                            product_discount_tf: tc_vars.product_discount_tf,
                            product_discount_ati: tc_vars.product_discount_ati,
                            product_engraving: tc_vars.product_engraving,
                            product_gravable: tc_vars.product_gravable,
                            product_id: tc_vars.product_id,
                            product_name: tc_vars.product_name,
                            product_promo: tc_vars.product_promo,
                            product_promo_label: tc_vars.product_promo_label,
                            product_quantity: tc_vars.product_quantity,
                            product_rating: tc_vars.product_rating,
                            product_size: tc_vars.product_size,
                            product_trademark: tc_vars.product_trademark,
                            product_unitprice_ati: tc_vars.product_unitprice_ati,
                            product_unitprice_tf: tc_vars.product_unitprice_tf
                        }
                    };

                    $(document).foundation('mastertag', 'track_tc_event', event);
                })
                // PARTAGE PAR MAIL
                .on('click', 'a.social-share-email', function (e) {

                    var reference = $(this).attr('data-product-reference');
                    var popinWrapper = $('#ajax-modal-small');

                    // Ouverture Popin
                    $.ajax(
                        {
                            cache: false,
                            async: true,
                            type: "GET",
                            url: '/Product/ModalShareByEmail',
                            data: { reference: reference },
                            success: function (data) {
                                popinWrapper.html(data).foundation('reveal', 'open');
                            },
                            beforeSend: function () {
                                $('#preloader').show()
                            },
                            complete: function () {
                                $('#preloader').hide();
                            }
                        });
                })
                // TOOLTIP
                .on('click', '.more-content .more', function (e) {
                    e.preventDefault();

                    var $elem = $(e.currentTarget);

                    var $parentWrapper = $elem.next();
                    $parentWrapper.show();

                })
                .on('click', '.payment-terms-wrapper .has-tooltip', function (e) {
                    e.preventDefault();
                    var $elem = $(e.currentTarget);

                    var $parentWrapper = $("#" + $elem.data('remote-id'));
                    $(".tooltip-term").hide();  // on ferme les autres tooltip
                    $parentWrapper.show();

                })
                .on('click', '.more-content .close', function (e) {
                    e.preventDefault();
                    var $elem = $(e.currentTarget).parent();
                    $elem.hide();

                })
                .on('click', '.tooltip-term .close-tooltip', function (e) {
                    e.preventDefault();
                    var $elem = $(e.currentTarget);
                    $elem.closest(".tooltip-term").hide();

                })
                // -- CLIC Ajout aux favoris > active le bouton
                .on('click', '.text-favoris', function (event) {
                    event.preventDefault();
                    $(event.currentTarget).siblings("button").trigger("click");
                })
                // CLICK VERS TABS
                // -- Avis clients
                .on('click', '.reviews-link', function (e) {
                    e.preventDefault();

                    if (this.hash.indexOf('small') == -1) { // Pour la version MEDIUM ou LARGE
                        $("#reviews-tab a").trigger("click");   // On ouvre l'onglet
                    }

                    $(document).foundation('scroll', 'moveTo', $(this.hash));
                })
                .on('click', '.characteristics-link', function (e) {
                    e.preventDefault();

                    $("#characteristics-tab a").trigger("click");   // On ouvre l'onglet                

                    $(document).foundation('scroll', 'moveTo', $(this.hash));
                })
                .on('click', '.product-back-button', function (e) {
                    e.preventDefault();

                    let backLocation = "/";
                    let referrer = document.referrer;
                    let currentLocation = window.location.href.replace("https://", "");
                    let currentLocationHost = currentLocation.substr(0, currentLocation.indexOf("/"));

                    if (referrer !== "" && referrer.includes(currentLocationHost)) {
                        referrer = referrer.replace("https://", "");
                        backLocation = referrer.substr(referrer.indexOf("/"));
                    }

                    window.location.href = backLocation;
                });
        },
        reflow: function () { },

        successAddProductToCart: function (data) {
            if (data.IsValid) {
                var opt = {};

                if (!data.HasEngraving) {
                    opt = {
                        product_engraving: '0',
                        product_size: data.ProductSize,
                    }
                }
                else {
                    opt = {
                        product_engraving: '1',
                        product_size: data.ProductSize,
                    }
                }

                // MAJ du datalayer
                $(document).foundation('common', 'refreshMasterTagData', data._MasterTagJson);
                $(document).foundation('common', 'refreshMasterTag');

                // Tracking via TagCo
                $(document).foundation('mastertag', 'trackAddToCart', { trigger: 'ajout_panier', category: 'ajout panier' });

                $(document).foundation('mastertag', 'track_tc_event',
                {
                    obj: this,
                    trigger: 'add_to_cart_confirmed',
                    options: opt
                });

                if (typeof data.UrlToRedirect !== "undefined") {
                    window.location = data.UrlToRedirect;
                }
                else {
                    $('#product-informations').html(data._ProductInformations);

                    // Feedback en affichant le survol du panier si on n'est pas sur mobile
                    Foundation.libs.common.clearLightCart();

                    // Affichage de la modale d'ajout au panier
                    var ref = data.Reference;

                    $.ajax({
                        url: '/Product/AddToCartModal',
                        data: { reference: ref },
                        success: function (result) {
                            if (result.IsValid) {
                                $('#ajout-produit-panier').html(result._AddProductModal)
                                $('#addProductReveal').foundation('reveal', 'open')
                                self.productReveal = new ProductReveal();

                                $(document).foundation('common', 'refreshMasterTagData', result._MasterTagJson);
                                $(document).foundation('common', 'refreshMasterTag');
                            }
                            Foundation.libs.common.hidePreloader();
                        },
                        beforeSend: function () {
                            Foundation.libs.common.showPreloader();
                        }
                    }).fail(function (e) {
                        Foundation.libs.common.hidePreloader();
                    });
                }
            }
            else {
                $('#erreur-globale .error-text').html(data.Message);
                $('#erreur-globale').foundation('reveal', 'open');
                Foundation.libs.common.hidePreloader();
            }

            $('#add-to-cart-button').removeAttr('disabled');
        },

        carouselViewsNext: function () {
            let index = $(".card.card-selected").index();

            if (index != $("#navigation .card").length - 1) {
                $("#navigation .card").removeClass('card-selected');

                $($("#navigation .card").get(index + 1)).addClass('card-selected');
            }
            this.sliderImages.trigger('next.owl.carousel');
            this.sliderNavigation.trigger('next.owl.carousel');
            /*if (this.sliderImagesZoom != null && this.sliderImagesZoom != "undefined") {
                this.sliderImagesZoom.trigger('next.owl.carousel');
            }*/
        },
        carouselViewsPrev: function () {
            let index = $("#navigation .card.card-selected").index();

            if (index != 0) {
                $("#navigation .card").removeClass('card-selected');

                $($("#navigation .card").get(index - 1)).addClass('card-selected');
            }
            this.sliderImages.trigger('prev.owl.carousel');
            this.sliderNavigation.trigger('prev.owl.carousel');
            /*if (this.sliderImagesZoom != null) {
                this.sliderImagesZoom.trigger('prev.owl.carousel');
            }*/

        },
        carouselViewsTo: function (index) {
            this.sliderImages.trigger('to.owl.carousel', [index, 300]);


            $("#navigation .card").removeClass('card-selected');

            $($("#navigation .card").get(index)).addClass('card-selected');

            if (this.sliderImagesZoom != null && typeof this.sliderImagesZoom.trigger === "function") {
                this.sliderImagesZoom.trigger('to.owl.carousel', [index, 300]);
            }
        },

        carouselZoomViewsTo: function (index) {

            $("#owl-product-slider-zoom-navigation .card").removeClass('card-selected');

            $($("owl-product-slider-zoom-navigation .card").get(index)).addClass('card-selected');

            if (this.sliderImagesZoom != null) {
                this.sliderImagesZoom.trigger('to.owl.carousel', [index, 300]);
            }
        },
        initCarouselZoom: function (activeView) {
            this.sliderImagesZoomElm = $('#owl-product-slider-zoom');
            this.sliderImagesZoomNavigationElm = $('#owl-product-slider-zoom-navigation');
            this.sliderImagesZoom = this.sliderImagesZoomElm.owlCarousel(this.sliderImagesZoomOpt);
            //this.sliderImagesZoomnavigation = this.sliderImagesZoomNavigationElm.owlCarousel(this.sliderImagesZoomNavigationOpt);

            this.sliderImagesZoom.trigger('to.owl.carousel', [activeView, 300]);

            $('#zoom-modal-wrapper').foundation('reveal', 'open');
            $('#zoom-modal-wrapper').on('opened', function () {
                $(document).scrollTop(0);
                $('#zoom-fiche-produit-wrapper').on('touchstart touchmove', function (event) {
                    event.stopImmediatePropagation();
                });
                $('#owl-product-slider-zoom').on('touchstart touchmove', function (event) {
                    event.stopImmediatePropagation();
                });
                $(document).foundation('product', 'initPanzoom', false);
            });

            this.sliderImagesZoom.on('changed.owl.carousel', function (property) {
                //$(document).scrollTop(0);
                $(document).foundation('product', 'initPanzoom', true);
            });
        },
        initPanzoom: function (destroy) {
            var previousTouchCoordinates = [0, 0];
            var previousScale = -1;

            // Récupération de toutes les images "zoom" du slider
            var zoomImages = $('#owl-product-slider-zoom').find("img");

            zoomImages.each(function () {

                if (destroy) {
                    // Destruction du panzoom de ces images pour éviter les problèmes de zoom intenpestif, d'image décalée, ect ect
                    $(this).panzoom("destroy");
                }

                //var current = property.item.index;
                //var img = $(property.target).find(".owl-item").eq(current).find("img");
                //var href = img.attr('data-href');

                var img = $(this);

                /* Calcul du facteur de zoom a appliquer pour éviter de trop grossir l'image */
                /* Récupération de la taille de l'image */
                var image_width = img.width();
                var image_height = img.height();

                /* Calcul des deux facteurs de zoom selon largeur et hauteur */
                var zoomFactorWidth = $('#owl-product-slider-zoom').width() / image_width;
                var zoomFactorHeight = $('#owl-product-slider-zoom').height() / image_height;

                /* Récupération du plus petit facteur selon la taille de l'image */
                var zoomFactor = Math.min(zoomFactorWidth, zoomFactorHeight);

                /* startTransform permet d'appliquer le facteur de zoom */
                /* disablePan doit être set a true pour éviter que l'image soit bougée par le plugin et sorte de l'écran */
                //img.attr("src", href).panzoom({
                img.panzoom({
                    startTransform: "scale(" + zoomFactor + ")",
                    minScale: 0.8,
                    maxScale: 2.5
                });

                // On reset le déplacement automatique du plugin qui décentre l'image
                img.panzoom("resetPan");

                // Récupération de la coordonnée sur l'axe Y du conteneur
                var parentTopPosition = $('#owl-product-slider-zoom').offset().top;

                // Récupération de la coordonnée sur l'axe Y de l'image + padding
                var imgTopPosition = img.position().top + (0.04 * $('#owl-product-slider-zoom').height());

                // Calcul du nombre de pixel à remonter
                var offsetTop = -1 * (imgTopPosition - parentTopPosition);

                // Déplacement sur l'axe Y de l'image
                img.panzoom("pan", 0, offsetTop);

                //$("#zoom-modal-wrapper .content").on('mousewheel.focal', function (e) {
                $("#zoom-fiche-produit-wrapper").on('mousewheel.focal', function (e) {
                    e.preventDefault();
                    var delta = e.delta || e.originalEvent.wheelDelta;
                    var zoomOut = delta ? delta < 0 : e.originalEvent.deltaY > 0;
                    img.panzoom('zoom', zoomOut, {
                        increment: 0.1,
                        animate: false,
                        focal: e
                    });
                });

                // Gestion du déplacement par touch et du zoom par pinch (mobile)

                img.on('touchstart', function (event) {
                    var originalEvent = event.originalEvent;

                    // un seul contact (un seul doigt)
                    if (originalEvent.touches.length === 1) {
                        previousTouchCoordinates[0] = originalEvent.touches[0].clientX;
                        previousTouchCoordinates[1] = originalEvent.touches[0].clientY;
                    }
                });

                img.on('touchmove', function (event) {
                    var originalEvent = event.originalEvent;

                    if (originalEvent.touches.length > 1) {

                        var scale = Math.abs(originalEvent.touches[0].clientX - originalEvent.touches[1].clientX);

                        if (previousScale > 0) {
                            if (scale > previousScale) {
                                img.panzoom('zoom', false, {
                                    increment: 0.05,
                                    animate: true
                                });
                            }
                            if (scale < previousScale) {
                                img.panzoom('zoom', true, {
                                    increment: 0.05,
                                    animate: true
                                });
                            }
                        }

                        previousScale = scale;
                    }
                    else if (originalEvent.touches.length === 1) {
                        var panLeft = originalEvent.touches[0].clientX - previousTouchCoordinates[0];
                        var panTop = originalEvent.touches[0].clientY - previousTouchCoordinates[1];

                        previousTouchCoordinates[0] = originalEvent.touches[0].clientX;
                        previousTouchCoordinates[1] = originalEvent.touches[0].clientY;

                        if (panTop !== 0 && panLeft !== 0) {
                            img.panzoom("pan", (panLeft / 2), (panTop / 2), { relative: true });
                        }
                    }
                });
            });
        },
       
    };
}(jQuery, window, window.document));

;
; (function ($, window, document, undefined) {
    'use strict';
    // nom de librairie à modifier
    Foundation.libs.gravure = {
        name: 'gravure',

        version: '1.0.0',

        settings: {
            callback: function () { }
        },
         
        init: function (scope, method, options) {
            // initialisation à conserver
            Foundation.inherit(this, '');
            var self = this;

            // à conserver
            this.bindings(method, options);
        },
        removeGravure : function(data) {
            var jqxhr = $.getJSON(
                "/ProductAction/RemoveGravure",
                {
                    referenceFormatee: data.referenceFormatee,
                    codeEmplacement: data.codeEmplacement
                }).always(data.callback).done($('#editEngraving').remove());
        },
        removeGravureFromShoppingCart: function (data) {
            $.ajax({
                url: '/CartAction/RemoveEngraving',
                method: "POST",
                data: {
                    optionId: data.optionId,
                    lineNumber: 0
                },
                success: function (result) {
                    $(document).foundation('cart', 'updateCart', result);
                    Foundation.libs.common.hidePreloader();
                    //$(document).foundation('reveal', 'close');
                },
                beforeSend: function () {
                    Foundation.libs.common.showPreloader();
                },
                always :data.callback
            });
        },
        events: function () {
            var self = this;
            var S = this.S;
            //////////////////////////////////////////////////////////////
            //                          ETAPE1                          //
            //////////////////////////////////////////////////////////////
            $(this.scope)
                .ready(function (event) {
                    //tres important pour eviter le cache pour les requetes JSON
                    $.ajaxSetup({ cache: false });
                })
                .on('click', '.checkbox-gravure', function (e) {
                    //console.log("***** checkbox gravure *****");
                    var $this = $(this);
                    var ref = $('#ReferenceFormatee').val();
                    var codeEmplacement = $(this).attr('data-code-emplacement');
                    var popinwidthclassname = $(this).attr('data-popin-width');
                    if (this.checked) {
                        e.preventDefault();
                        $('#popin-gravure-wrapper').attr('data-mq-class-large', popinwidthclassname);
                        $('#popin-gravure-wrapper').mqClass();
                        $('#popin-gravure-wrapper').foundation('reveal', 'open', {
                            url: '/product/LoadGravureFormEmplacement',
                            data: { referenceFormatee: ref, codeEmplacement: codeEmplacement },
                            success: function (data) {
                            },
                            error: function () {
                            }
                        });
                    }
                    else {
                        var jqxhr = $.getJSON("/ProductAction/RemoveGravure", { referenceFormatee: ref, codeEmplacement: codeEmplacement })
                            .always(function (data) {
                                $this.siblings('.update-gravure').hide();
                            });
                    }
                })
                .on('click', '.checkbox-gravure-inline', function (e) {
                    //console.log("***** checkbox gravure inline *****");
                    var $this = $(this);
                    var ref = $('#Reference').val();
                    var codeEmplacement = $(this).attr('data-code-emplacement');
                    var numeroLigne = $(this).attr('data-line-id');
                    var optionId = $(this).attr('data-option-id');
                    var targetWrapper = $(".personnalisation-form-wrapper");

                    if (this.checked) {
                        e.preventDefault();

                        $.ajax({
                            url: '/engraving/LoadEngravingPreview',
                            data: { referenceFormatee: ref, codeEmplacement: codeEmplacement, itemId: numeroLigne },
                            cache: false,
                            beforeSend: function (data) {
                                $('#preloader').show();
                            },
                            success: function (result) {
                                if (result.IsValid) {
                                    if (result.IsPreview) {
                                        $('#engraving-preview-modal').html(result._Preview);
                                        $('#engraving-preview-modal').foundation('reveal', 'open');
                                        Foundation.libs.gravure.bindInputsToSvg();

                                        document.body.style.overflow = 'hidden';
                                    }
                                    else {
                                        targetWrapper.html(result._EngravingForm).fadeIn();
                                        $(document).foundation('scroll', 'moveTo', $('#personnalisation-form-wrapper-anchor'));
                                    }

                                    // Tracking via TagCo
                                    $(document).foundation('mastertag', 'track_tc_event',
                                    {
                                        obj: this,
                                        trigger: 'saisie_gravure',
                                        options: {
                                            category: 'gravure',
                                            action: 'saisie gravure',
                                            label: tc_vars.product_name + ' - ' +tc_vars.product_id,
                                            value: tc_vars.product_unitprice_ati
                                        }
                                    });
                                }
                            },
                            complete: function (data) {
                                $('#preloader').fadeOut();
                            }
                        });
                    }
                    else {
                        $('#ajax-modal-small').foundation('reveal', 'open', {
                            url: '/Product/ConfirmRemoveGravure',
                            data: { referenceFormatee: ref, codeEmplacement: codeEmplacement, optionId: optionId, idLigne: numeroLigne }
                        });
                    }
                })
                .on("click", "#engraving-preview-modal .close-reveal-modal", function (e) {
                    document.body.style.overflow = 'visible';
                })
                .on('click', '.update-gravure-inline', function (e) {
                    console.log("***** update gravure inline *****");
                    e.preventDefault();
                    var ref = $('#ReferenceFormatee').val();
                    var codeEmplacement = $(this).attr('data-code-emplacement');
                    //var popinwidthclassname = $(this).attr('data-popin-width');

                    //$('#popin-gravure-wrapper').attr('data-mq-class-large', popinwidthclassname);
                    //$('#popin-gravure-wrapper').mqClass();
                    //$('#popin-gravure-wrapper').foundation('reveal', 'open', {
                    //    url: '/product/LoadGravureFormEmplacement',
                    //    data: { referenceFormatee: ref, codeEmplacement: codeEmplacement },
                    //    success: function (data) {
                    //        console.log("1 fois");
                    //    },
                    //    error: function () {
                    //    }
                    //})
                    var targetWrapper = $(".personnalisation-form-wrapper");
                    $.ajax({
                        url: '/product/LoadGravureFormEmplacement',
                        data: { referenceFormatee: ref, codeEmplacement: codeEmplacement, template: "inline" },
                        cache: false,
                        dataType: "html",
                        beforeSend: function (data) {
                            $('#preloader').show();
                        },
                        success: function (data) {
                            targetWrapper.html(data).fadeIn();
                            $(document).foundation('scroll', 'moveTo', $('#personnalisation-form-wrapper-anchor'));
                        },
                        complete: function (data) {
                            $('#preloader').fadeOut();
                        }
                    });
                })
                .on('click', '.update-gravure', function (e) {
                    console.log("***** update gravure *****");
                    e.preventDefault();
                    var ref = $('#ReferenceFormatee').val();
                    var codeEmplacement = $(this).attr('data-code-emplacement');
                    var popinwidthclassname = $(this).attr('data-popin-width');

                    $('#popin-gravure-wrapper').attr('data-mq-class-large', popinwidthclassname);
                    $('#popin-gravure-wrapper').mqClass();
                    $('#popin-gravure-wrapper').foundation('reveal', 'open', {
                        url: '/product/LoadGravureFormEmplacement',
                        data: { referenceFormatee: ref, codeEmplacement: codeEmplacement },
                        success: function (data) {
                            console.log("1 fois");
                        },
                        error: function () {
                        }
                    })
                })
                .on('click touchend', '.upload-file', function (e) {
                    // Au click sur le fake bouton file on simule le click sur le vrai bouton file qui est plus petit...
                    e.preventDefault();
                    $('#PieceJointe').trigger('click');
                })
                .on('change', '#PieceJointe', function () {
                    //var filename = $(document).foundation('common', 'GetFileName', $(this));
                    var filename = Foundation.libs.common.getFileName($(this));
                    var filesize = Foundation.libs.common.getSizeUploadedFile($(this));

                    var maxfilesize = $('#hMaxUploadGravure').val();

                    if (filename != null) {
                        if (!filename.match('jpg|jpeg|gif|png$')) {
                            $('#PieceJointeCustomerFileName').val('');

                            $('#upload-section').hide();
                            $('#upload-information-section').show();
                            $('#txtAvecPJ').html('nous en prenons pas en compte ce type de fichier (' + filename + ')');
                            $('#txtSansPJ').css('display', 'block');
                            $('#txtSansPJ').css('display', 'none');
                        }
                        else if (filesize > maxfilesize) {
                            $('#PieceJointeCustomerFileName').val('');

                            $('#upload-section').hide();
                            $('#upload-information-section').show();
                            $('#txtAvecPJ').html('le fichier que vous avez choisi est trop volumineux');
                            $('#txtSansPJ').css('display', 'block');
                            $('#txtSansPJ').css('display', 'none');
                        }
                        else {
                            $('#upload-section').hide();
                            $('#upload-information-section').show();
                            $('#txtAvecPJ').html('Votre fichier : ' + filename);
                            $('#txtSansPJ').css('display', 'block');
                            $('#txtSansPJ').css('display', 'none');
                        }
                    }
                    else {
                        $('#PieceJointeCustomerFileName').val('');

                        $('#upload-information-section').hide();
                        $('#upload-section').show();
                        $('#txtAvecPJ').css('display', 'none');
                        $('#txtSansPJ').css('display', 'block');
                    }
                })
                .on('click', '.remove-uploaded-file', function (e) {
                    e.preventDefault();
                    $('#PieceJointeCustomerFileName').val('');

                    $('#upload-information-section').hide();
                    $('#upload-section').show();
                })
                .on('click', '.bt-font-family-choice', function (e) {
                    const target = e.currentTarget;
                    const form = document.getElementById('form-submit-engraving');
                    const reference = form.elements['Reference'].value;
                    const locationCode = form.elements['LocationCode'].value;
                    const itemId = form.elements['ItemId'].value;
                    const selectedFont = target.dataset["fontfamily"];
                    const templateId = target.dataset["templateid"];
                    const allInputs = document.querySelectorAll('.engraving-zone-text-input');
                    let zones = [];

                    for (let i = 0; i < allInputs.length; i++) {
                        let zone = {
                            ZoneId: $(allInputs[i]).data("zone-id"),
                            Text: $(allInputs[i]).val(),
                            //OriginalText: $(allInputs[i]).data("original-text"),
                            MaxCharSize: $(allInputs[i]).data("max-char-size")
                        }

                        zones.push(zone);
                    }

                    $.ajax({
                        type: 'POST',
                        url: '/engraving/ChangeTemplateFontFamily',
                        data: { reference: reference, locationCode: locationCode, itemId: itemId, fontFamily: selectedFont, templateId: templateId, zones: zones },
                        beforeSend: function () {
                            Foundation.libs.common.showPreloader();
                        },
                        success: function (result) {
                            if (result.IsValid) {
                                if (result.IsCart === false) {
                                    $('#engraving-preview-modal').html(result._EngravingPreview);
                                } else {
                                    $('#m-gravure-container-' + result.ItemId).html(result._EngravingPreview);
                                }

                                Foundation.libs.gravure.bindInputsToSvg();
                            }
                            Foundation.libs.common.hidePreloader();
                        },
                        failure: function () {
                            Foundation.libs.common.hidePreloader();
                        }
                    });
                })
                .on('click', '.update-engraving-with-preview', function (e) {
                    const ref = $(this).attr('data-reference');
                    const codeEmplacement = $(this).attr('data-code-emplacement');
                    const fontFamily = $(this).attr('data-font-family');

                    $.ajax({
                        url: '/engraving/LoadEngravingPreview',
                        data: { referenceFormatee: ref, codeEmplacement: codeEmplacement, fontFamily: fontFamily },
                        cache: false,
                        beforeSend: function (data) {
                            $('#preloader').show();
                        },
                        success: function (result) {
                            if (result.IsValid) {
                                $('#engraving-preview-modal').html(result._Preview);
                                $('#engraving-preview-modal').foundation('reveal', 'open');
                                document.body.style.overflow = 'hidden';
                                Foundation.libs.gravure.bindInputsToSvg();
                                Foundation.libs.common.trackGAEvent({ category: 'gravure', action: 'saisie gravure' });
                            }
                        },
                        complete: function (data) {
                            $('#preloader').fadeOut();
                        }
                    });
                })
                .on('click', '.cancel-update-cart-engraving', function (e) {
                    e.preventDefault();
                    e.stopImmediatePropagation();

                    const target = e.currentTarget;
                    const itemId = $(target).data("item-id");

                    $.ajax({
                        type: 'POST',
                        url: '/engraving/CancelUpdateEngravingFromCart',
                        data: { itemId: itemId },
                        beforeSend: function () {
                            Foundation.libs.common.showPreloader();
                        },
                        success: function (result) {
                            if (result.IsValid) {
                                $('#cart-item-engravings-' + result.ItemId).html(result._Engravings);
                                Foundation.libs.common.hidePreloader();
                            }
                        },
                        failure: function () {
                            Foundation.libs.common.hidePreloader();
                        }
                    });
                })
                .on('click', '.engraving-tab', function (e) {
                    e.preventDefault();
                    e.stopImmediatePropagation();

                    const target = e.currentTarget;
                    const contentTarget = target.firstElementChild.hash;
                    const allTabs = document.querySelectorAll('.engraving-tab');
                    const allContents = document.querySelectorAll('.engraving-tab-content');
                    const form = document.getElementById("form-submit-engraving");

                    for (let i = 0; i < allTabs.length; i++) {
                        if (allTabs[i].classList.contains("active")) {
                            $(allTabs[i]).removeClass("active");
                        }
                    }

                    for (let i = 0; i < allContents.length; i++) {
                        if (allContents[i].classList.contains("active")) {
                            $(allContents[i]).removeClass("active");
                        }
                    }

                    $(target).addClass("active");
                    $(contentTarget).addClass("active");

                    form.elements['SelectedTemplateId'].value = contentTarget.replace("#template-", "");
                })
                .on('submit', '#form-submit-engraving', function (e) {
                    
                    for (let i = 0; i < e.currentTarget.elements.length; i++) {
                        if (e.currentTarget.elements[i].classList.contains("engraving-zone-text-input")) {
                            const value = e.currentTarget.elements[i].value.toString().replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, '');

                            e.currentTarget.elements[i].value = value;
                        }
                    }
                });
        },

        reflow: function () {
            this.events();
        },

        bindInputsToSvg: function () {
            const allInputs = document.querySelectorAll('.engraving-zone-text-input');

            for (let i = 0; i < allInputs.length; i++) {
                const templateId = $(allInputs[i]).data("template-id");
                const tspanId = $(allInputs[i]).data("tspan-id");
                const isAllCaps = $(allInputs[i]).data("is-all-caps") === "True";
                const template = document.querySelector("#engraving-preview-visual-" + templateId);
                const tspan = template.querySelector("#" + tspanId);
                let currentInputValue = $(allInputs[i]).val();

                if (isAllCaps) {
                    currentInputValue = currentInputValue.toUpperCase();
                }

                $(tspan).html(currentInputValue);

                allInputs[i].addEventListener('keyup', function (e) {
                    let value = e.currentTarget.value.toString().replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, '');

                    if (isAllCaps) {
                        value = value.toUpperCase();
                    }

                    $(tspan).html(value);
                });
            }
        },

        successShowAddEngravingFromCart: function (result) {
            if (result.IsValid) {
                if (result.IsRedirect) {
                    window.location.href = result.Redirect;
                } else {
                    $('#m-gravure-container-' + result.ItemId).html(result._Preview);
                    $('#m-gravure-container-' + result.ItemId).addClass("-open");
                   

                    Foundation.libs.gravure.bindInputsToSvg();
                    Foundation.libs.common.trackGAEvent({ category: 'gravure', action: 'saisie gravure' });
                    Foundation.libs.common.hidePreloader();
                    Foundation.libs.gravure.reflow();
                }
            }
        },

        successShowUpdateEngravingFromCart: function (result) {
            if (result.IsValid) {
                $('#m-gravure-container-' + result.ItemId).html(result._Preview);

                Foundation.libs.gravure.bindInputsToSvg();
                Foundation.libs.common.trackGAEvent({ category: 'gravure', action: 'saisie gravure' });
                Foundation.libs.common.hidePreloader();
                Foundation.libs.gravure.reflow();
            }
        },

        successSubmitEngraving: function (result) {
            if (result.IsValid) {
                $('#engraving-preview-modal').foundation('reveal', 'close');
                document.body.style.overflow = 'visible';

                if (result.IsUpdateCart === false) {
                    $('#engraving-input-checkbox-wrapper').html(result._EngravingChoices);
                }
                else if (result.IsUpdateCart) {
                    Foundation.libs.cart.updateComponent("etape1Panier", result._SectionTotalBasket);
                    Foundation.libs.cart.initBindings();

                    $(document).foundation('common', 'refreshMasterTagData', result._MasterTagJson);
                    $(document).foundation('common', 'refreshMasterTag');
                }

                // Tracking via TagCo
                $(document).foundation('mastertag', 'track_tc_event',
                {
                    obj: this,
                    trigger: 'validation_gravure',
                    options: {
                        category: 'gravure',
                        action: 'validation gravure',
                        label: result.ItemTitle + ' - ' + result.ItemReference,
                        value: result.ItemPrice
                    }
                });
            }

            Foundation.libs.common.hidePreloader();
        }
    };
}(jQuery, window, window.document));

;
(function () {
    $('.aide-taille').on('click', function (e) {
        // Tracking via TagCo
        $(document).foundation('mastertag', 'track_tc_event',
        {
            obj: this,
            trigger: 'clic_guide_tailles',
            options: {
                category: 'taille',
                action: 'guide des tailles'
            }
        });
    });
}).call(this);

function OnSuccessGravure(response) {
    if (tc_vars['env_work'] != 'PRODUCTION') {
        console.log("Réponse reçue après validation gravure :");
        console.log($(response).attr('id'));
    }

    if ($(response).attr('id') == 'gravure-edit-form') {
        $('.personnalisation-form-wrapper').html(response);
        $('#preloader').fadeOut();
    }
    else {
        // Tracking via TagCo
        $(document).foundation('mastertag', 'track_tc_event',
        {
            obj: this,
            trigger: 'validation_gravure',
            options: {
                category: 'gravure',
                action: 'validation gravure',
                label: tc_vars['product_name'] + ' - ' + tc_vars['product_id'],
                value: tc_vars['product_unitprice_ati']
            }
        });

        if (response.PopinConfirmationUrl != undefined) {
            $("#preloader").fadeOut();
            $('#ajax-modal-small').foundation('reveal', 'open', {
                url: response.PopinConfirmationUrl
            });
        }
        else {
            window.location = response.Redirection;
        }
    }
}

function OnShareByEmailSuccess(result) {
    var popinWrapper = $('#ajax-modal-small');
    popinWrapper.html(result);
}

function OnShareByEmailFailure(result) {
    var popinWrapper = $('#ajax-modal-small');
    popinWrapper.html(result);
}

function BeforeUpdateInlineGravureForm(response) { 
    $("#preloader").show();
}

function DisableButton() {
    $("#retrait-bijouterie-wrapper button").attr("disabled", "disabled");
}

function EnableButton() {
    $("#retrait-bijouterie-wrapper button").removeAttr("disabled");
}

// Mise à jour formulaire ClickNCollect
function OnSuccessCNCAvailability(response) {
    $("#retrait-bijouterie-wrapper").html(response);

    EnableButton();

    Foundation.libs.common.hidePreloader();
}

function OnFailureCNCAvailability(response) {
    // On réactive les boutons
    EnableButton();
}

// Mise à jour formulaire ClickNCollect
function OnSuccessCNCBook(response) {
    const event = {
        obj: "",
        trigger: "e_reservation",
        options: {
            category: "validation e-reservation",
            action: tc_vars.product_category,
            label: tc_vars.product_name + "|" + tc_vars.product_id,
            value: tc_vars.product_unitprice_ati,
            product_brand: tc_vars.product_trademark,
            product_cat1: tc_vars.product_cat1,
            product_cat2: tc_vars.product_cat2,
            product_cat3: tc_vars.product_cat3,
            product_category: tc_vars.product_category,
            product_currency: tc_vars.product_currency,
            product_discount_tf: tc_vars.product_discount_tf,
            product_discount_ati: tc_vars.product_discount_ati,
            product_engraving: tc_vars.product_engraving,
            product_gravable: tc_vars.product_gravable,
            product_id: tc_vars.product_id,
            product_name: tc_vars.product_name,
            product_promo: tc_vars.product_promo,
            product_promo_label: tc_vars.product_promo_label,
            product_quantity: tc_vars.product_quantity,
            product_rating: tc_vars.product_rating,
            product_size: tc_vars.product_size,
            product_trademark: tc_vars.product_trademark,
            product_unitprice_ati: tc_vars.product_unitprice_ati,
            product_unitprice_tf: tc_vars.product_unitprice_tf
        }
    };

    $(document).foundation('mastertag', 'track_tc_event', event);

    $("#retrait-bijouterie-wrapper").html(response);

    EnableButton();
}

function OnFailureCNCBook(response) {
    // On réactive les boutons
    EnableButton();
};
$(document).ready(function () {
    $(".rate-bar--list .rate-bar--item").bind("click", function (event) {
        event.preventDefault();
        updateReviewList($(this).data('reference'), $(this).data("note"));
        $("#rate-filter").val($(this).data("note"));
    });

    $("#rate-filter").on("change", function () {

        updateReviewList($(this).attr('data-reference'), this.value);
    });
});

function updateReviewList(reference,filtre) {
    $.ajax({
        type: "POST",
        url: '/product/GetReviews',
        data: {
            reference: reference,
            filtre: filtre 
        },
        success: function (data) {
            $('.modifjs').html(data);
            Foundation.libs.common.hidePreloader();
        },
        error: function () {
            Foundation.libs.common.hidePreloader();
        },
        beforeSend: function () {
            Foundation.libs.common.showPreloader();
        }
    });
};
$(document).ready(function () {
    bindButtons();
});

function OnSuccessBet(result) {
    if (result.IsValid) {
        if (result._Availabilities != null) {
            $("#availability-wrapper").html(result._Availabilities);
            
        }
        if (result._BetInformations != null) {
            $("#auction-bet-wrapper").html(result._BetInformations);
        }
    }
    else {
        if (result._BetInformations != null) {
            $("#auction-bet-wrapper").html(result._BetInformations);
        }
    }
    bindButtons();
    Foundation.libs.common.hidePreloader();
}

function OnSuccessAuctionPhoneAlert(result) {
    if (result._PhoneAlert != null) {
        $("#form-aution-phone-alert").html(result._PhoneAlert);
    }

    if (result.IsValid) {
        var label = document.getElementById('phonealert-label');

        if (label !== undefined) {
            label.style.display = 'none';
        }
    }
    else {
        var collapse = document.getElementById('phonealert-collapse');
        var wrapper = document.getElementById('phonealert-wrapper');

        if (collapse !== undefined && wrapper !== undefined) {
            collapse.style.display = 'none';
            wrapper.style.display = '';
        }
    }

    Foundation.libs.common.hidePreloader();
}

function AtTheEndOfAuction() {
    // Uniquement sur la page Produit (avec zone-encherir donc)
    if ($("#zone-encherir").length) {
        $("#zone-encherir").hide();
        Foundation.libs.common.showPreloader();
        location.replace(location.pathname);

        //// [id^=LastAuctionCustomerAccount] -> id commençant par 'LastAuctionCustomerAccount'
        //if ($("#Auction_AuctionCustomerAccount").val() == $('[id^=LastAuctionCustomerAccount]').val()) {
        //    // Plusieurs solutions : 
        //    // 1 :
        //    //$("#auction_message").text("Vous avez remporté l'enchère.");
        //    // + SignalR vers serveur executer une fonction 'fin enchère' (envoi mail ? ajout au panier ? si ajout panier : pb MAJ affichage Panier)
        //    // 2 : 
        //    // On recharge la page (prévoir un test pour savoir la fonction 'fin enchère' doit être executée (utilisation d'un flag ?))
        //    // Le fait de recharcher simplifie la problèmatique de MAJ affichage (du Panier par exemple)
        //    location.replace(location.pathname)
        //}
        //else {
        //    $("#auction_message").text("Malheureusement vous n'avez pas remporté cette enchère.");
        //}
    }
}

function bindButtons() {
    $("#form-bet input").bind("keyup", function (event) {
        let val = $(this).val();

        $("#form-bet button").html("Je mise " + val + " €");
    });

    $('#auction-page-wrapper .more-infos').bind("click", function (event) {
        event.preventDefault();
        var id = $(this).attr("href");

        if ($(window).width() >= 650) {
            var top = $(id).offset().top - 40;

            $('html, body').animate({
                scrollTop: top
            });

            $(id).find("a").trigger("click");
        } else {
            var target = $(id).find("a").attr("href");

            $(target).removeClass("active");

            $('html, body').animate({
                scrollTop: $(target).offset().top
            });
        }
    });

    $('#btn-phonealert-collapse').bind("click", function (event) {
        event.preventDefault();

        var collapse = document.getElementById('phonealert-collapse');
        var wrapper = document.getElementById('phonealert-wrapper');
        var label = document.getElementById('phonealert-label');

        if (collapse !== undefined && wrapper !== undefined) {
            collapse.style.display = 'none';
            wrapper.style.display = '';
            label.innerHTML = "Entrez votre numéro de téléphone mobile et recevez un SMS dès le lancement de l'enchère";
        }
    });
};
