﻿
$(document).ready(function () {
    scriptFunction();
});
$(window).load(function () {
    document.getElementById('addButton').disabled = false;
    document.getElementById('counter').value = 0;
    searchInWallpaper();
});

$('#sort').on('change', function (ev) {
    document.getElementById('divWaiting').style.display = "block";
    document.getElementById('counter').value = "0";
    searchInWallpaper();
    document.getElementById('divWaiting').style.display = "none";
});
$('#sortDesc').on('change', function (ev) {
    document.getElementById('divWaiting').style.display = "block";
    document.getElementById('counter').value = "0";
    searchInWallpaper();
});
$(window).bind("load", function () {
    //slider, carusel

    $('.product-slider .owl-carousel').owlCarousel({
        rtl: true,
        loop: true,
        margin: 0,
        nav: true,
        smartSpeed: 1000,
        responsive: {
            0: {
                items: 1
            },
            600: {
                items: 3
            },
            1000: {
                items: 4
            }
        }
    })

    $('.product-carousel .owl-carousel').owlCarousel({
        rtl: true,
        nav: true,
        responsive: {
            0: {
                items: 1
            },
            600: {
                items: 1
            },
            1000: {
                items: 1
            }
        }
    });

    //panels1
    $("#panels1 .panel-title a").click(function () {
        $(this).children('.icon').toggleClass("down");
    });

    $("#panels1 .tree-toggle").click(function () {
        $(this).children('span').toggleClass("down");
    });
});

function scriptFunction() {
    //product-single
    $(".product-single .thumbnail").hover(function () {
        $(this).find("img.first").animate({
            opacity: 0
        });
    }, function () {
        $(this).find("img.first").animate({
            opacity: 100
        });
    });

    // simple-collapse-wrapper
    $(".simple-collapse-wrapper .product-single .order-s").click(function (e) {
        e.preventDefault();

        //toggle collapse
        $(this).parents(".simple-collapse-wrapper").find(".collapse.in").collapse('hide');

        var _collapse = $(this).parents(".product-single").children(".simple-collapse");
        var _first = $(".simple-collapse-wrapper .product-single:first");
        var _last = $(".simple-collapse-wrapper .product-single:last");
        var _curr = $(this).parents(".product-single");
        var _pos_first = _first.position();
        var _pos_curr = _curr.position();

        //console.log(_curr.width()/2+_pos_curr.left);
        _collapse.find('.arrow').css({
            left: _curr.width() / 2 + _pos_curr.left + 'px'
        });

        var _pos_next = _curr.next().position();
        var _index = _curr.index();
        var _class = "st-" + _index;

        if (_curr.hasClass('has-toggle')) {
            return;
        }

        var _target = function (_current) {
            var __curr;
            if (_current.next().hasClass('product-single')) {
                if (_current.next().position().left == _pos_first.left) {
                    __curr = _current;
                } else {
                    _target(_current.next());
                }
            } else {
                //console.log('is end');
                __curr = _current;
            }
            _collapse.insertAfter(__curr);
            _curr.addClass('has-toggle');
            //console.log('finish');
        };
        _target(_curr);
    });

    //nicescroll
    if ($(".nscroll").length) {
        $(".nscroll").niceScroll({
            railalign: 'left',
            rtlmode: true
        });
    }

    

    
    var stf2 = function () {
        $(".sticky-notify").removeClass('active');

    }
    
    $(".closeNot").click(stf2)
}

//hover list trigger
var hlt_f = function (el) {
    var hlt_w = el.find('.hlt-w');
    hlt_w.hover(function () {
        hlt_w.children('.hlt-c').show(100);
    }, function () {
        setTimeout(function () {
            hlt_w.children('.hlt-c').hide();
        }, 100);
    });
};
hlt_f($('.basket-c'));
//hlt_f($('.search-c'));

if (typeof $('#ex2').slider() !== "undefined") {
    $('#ex2').slider().on('slideStop', function (ev) {
        setPrice();

    });
}