(function() {
    'use strict';

    var website = openerp.website;
    website.openerp_website = {};

    website.snippet.animationRegistry.kingfisher_product_slider = website.snippet.Animation.extend({
        selector: ".oe_product_slider",
        start: function(editable_mode) {
            var self = this;
            if (editable_mode) {
                $('.oe_product_slider > .div.slider_product_slider').addClass("hidden");
            }
            if (!editable_mode) {
                $.post("/shop/get_products_slider", {
                    'product_count': self.$target.attr('data-product-count') || 0,
                    'slider_type': self.$target.attr('data-slider-type') || '',
                    'product_label': self.$target.attr('data-product-label') || '',
                }, function(data) {
                    if (data) {
                        self.$target.empty().append(data);
                        $(".oe_product_slider").removeClass('hidden');
                        var script1 = document.createElement("script")
                        script1.type = "text/javascript";

                        if (script1.readyState) { //IE
                            script1.onreadystatechange = function() {
                                if (script1.readyState == "loaded" || script1.readyState == "complete") {
                                    script.onreadystatechange = null;
                                    // callback();
                                }
                            };
                        } else { //Others
                            script1.onload = function() {
                                // callback();
                            };
                        }

                        script1.src = '/kingfisher/static/src/js/owl.carousel.min.js';

                        var script = document.createElement("script")
                        script.type = "text/javascript";

                        if (script.readyState) { //IE
                            script.onreadystatechange = function() {
                                if (script.readyState == "loaded" || script.readyState == "complete") {
                                    script.onreadystatechange = null;
                                    // callback();
                                }
                            };
                        } else { //Others
                            script.onload = function() {
                                // callback();
                            };
                        }

                        script.src = '/kingfisher/static/src/js/custom.js';
                        document.getElementsByTagName("body")[0].appendChild(script);
                    }
                });
            }
        }
    });
})();
