﻿GNS.notification = {
    $modal: $('#notification_modal'),
    $body: $('#notification_modal_body'),
    onCloseCallback: undefined,
    show: function (message, onCloseCallback) {
        var self = this;

        self.$body.html(message || '');
        self.onCloseCallback = onCloseCallback || undefined;

        self.$modal.on('hidden.bs.modal', function () {
            if (self.onCloseCallback) {
                self.onCloseCallback();
                self.onCloseCallback = undefined;
            }
        });

        self.$modal.modal('show');
    },
    hide: function () {
        this.$modal.modal('hide');
    }
};

$(document).ready(function () {
    // For default events for open/close menu
    $("[data-dropdown-arrow]").click(function () {
        var $this = $(this),
            $icon = $this,
            $block = $this.closest("[data-dropdown-block]"),
            $list = $block.find("[data-dropdown-list]").eq(0);

        if ($this.hasClass("active")) {
            $this.removeClass("active");
            $icon.css("transform", "rotateX(" + 0 + "deg)");
            $list.slideUp(400);
        } else {
            $this.addClass("active");
            $icon.css("transform", "rotateX(" + 180 + "deg)");
            $list.slideDown(400);
        }
    });
    // END

    // init tooltip
    $('[data-toggle="tooltip"]').tooltipster();
    // $('[data-toggle="tooltip"]').tooltip({
    //     animated: 'fade',
    //     placement: 'top',
    //     //container: 'body'
    // });
    // END

    // button to top
    $('#toTop').click(function() {
        $('body,html').animate({ scrollTop: 0 }, 800);
    });
    // END

    // init matchHeight
    $("[data-height], .slider_item:not(.sale_slider-item) .slider_product-img").matchHeight({
        byRow: true,
        property: 'height',
        target: null,
        remove: false
    });
    // END

    $('input[name="language_checkbox"]').on('change', function () {
        window.location.href = $(this).attr('data-language-url')
    });

    // breadcrumbTrim();
});

$(window).scroll(function () {
    //if ($(this).scrollTop() > 0) { $(".top_btn").fadeIn(); }
    if ($(this).scrollTop() > $("header").height()) {
        $("#toTop").fadeIn(600);
    } else {
        $("#toTop").fadeOut(400);
    }
});

$(window).on("load", function () {
    // Wish list product
    if (!GNS.isUserAuth) {
        $('body').on('click', '[data-wish-list-products-count], [data-wish-list-product]', function (e) {
            e.preventDefault();
            e.stopPropagation();

            $('#auth_modal').modal('show');

            return false;
        });
    }

    // Shows session notification message
    if (GNS.notificationMessage) {
        GNS.notification.show(GNS.notificationMessage);
    }
});

$(window).resize(function () {
    // breadcrumbTrim();
});

// function breadcrumbTrim() {
//     var bc = $(".breadcrumbs_block"), // ul parent container
//         bcWidth = bc.width(),
//         bcWidthMin = bcWidth - 35,
//         bcFull = $(".breadcrumbs_list"),
//         bcFullWidth = 0;
//
//     $(".breadcrumbs_list li").each(function (i, el) {
//         bcFullWidth = bcFullWidth + $(this).width();
//     });
//
//     if (bcWidth < bcFullWidth) {
//         bcFull.css({ "width": bcWidthMin + "px", "overflow": "hidden" });
//         bc.addClass("bcAfter");
//     } else {
//         bcFull.removeAttr("style");
//         bc.removeClass("bcAfter");
//     }
// }
