$(function () {

    $('.dropdown').hover(function () {
        $(this).addClass('open');
    }, function () {
        $(this).removeClass('open');
    });

    // 右侧滑动返回顶部
    var time;
    var $client = $('.client-2');
    var $c = $client.find('#client-2');
    $client.css({
        'marginTop': -($client.height() / 2)
    });
    $c.find('li').on({
        'mouseenter': function () {
            var scope = this;
            time = setTimeout(function () {
                var divDom = $(scope).children('div');
                var maxWidth = divDom.width();
                $(scope).stop().animate({
                    left: 77 - maxWidth
                }, 'normal', function () {
                    var pic = $(scope).find('.my-kefu-weixin-pic');
                    if (pic.length > 0) {
                        pic.show();
                    }
                });
            }, 100);
        },
        'mouseleave': function () {
            var pic = $(this).find('.my-kefu-weixin-pic');
            if (pic.length > 0) {
                pic.hide();
            }
            clearTimeout(time);
            $(this).stop().animate({
                left: 0
            }, 'normal', function () {
            });
        }
    });
    $(window).scroll(function () {
        var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
        var eltop = $c.find('.my-kefu-ftop');
        if (scrollTop > 0) {
            eltop.show();
        } else {
            eltop.hide();
        }

        var oTop = $(document).scrollTop();
        if (oTop > 300) {
            $('.yunu-header-fix').stop().animate({ 'top': '0' }, 300);
        }
        else {
            $('.yunu-header-fix').stop().animate({ 'top': '-83' }, 300);
        }

    });
    $c.find('.my-kefu-ftop').click(function () {
        var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
        if (scrollTop > 0) {
            $('html,body').animate({
                scrollTop: 0
            }, 'slow');
        }
    });
});


function msw_jzt(ID, btnLeft, btnRight, elment, title, speed, number, pre) {
    var _ID = $('#' + ID + '');
    var _BtnLeft = $('#' + btnLeft + '');
    var _BtnRight = $('#' + btnRight + '');
    var _elment = $('#' + ID + ' .' + elment + '');
    var len = $('#' + ID + ' .' + elment + '').length;
    var number = number;
    var pfnum = (number - 1) / 2;
    var jsq = 0;
    var active = 0;


    _ID.width('100%').height('100%').css({'position': 'relative', 'z-index': 1});
    _elment.find('img').css({'width': '100%', 'display': 'block'});
    _elment.css({'width': '30%', 'left': '35%', 'top': '5%', 'z-index': 0, 'position': ' absolute'});
    _elment.eq(pfnum).css({
        'width': '' + pre + '%',
        'left': '' + (100 - pre) / 2 + '%',
        'top': '0',
        'z-index': number
    }).addClass('active');
    _elment.find('' + title + '').hide();
    _elment.eq(pfnum).find('' + title + '').show();
    for (i = 1, th = pfnum; i < pfnum + 1; i++) {

        _elment.eq(th + i).css({
            'width': '' + (pre - 10 * i) + '%',
            'left': '' + (100 - pre) * 0.5 / pfnum * (pfnum - i) + '%',
            'top': '' + 7.5 * i + '%',
            'z-index': number - i
        });

        _elment.eq(th - i).css({
            'width': '' + (pre - 10 * i) + '%',
            'left': '' + 100 - (pre - 10 * i) - (100 - pre) * 0.5 / pfnum * (pfnum - i) + '%',
            'top': '' + 7.5 * i + '%',
            'z-index': number - i
        });

    }

    var time = new Date;

    _BtnLeft.hover(function () {
        clearInterval(t);
    }, function () {
        t = setInterval(car, 4000);
    }).click(function () {
        if (new Date - time > 500) {
            time = new Date;
            $('#' + ID + ' .' + elment + ':first').animate({width: '30%', left: '35%', top: '5%'}).css({'z-index': 0});
            $('#' + ID + ' .' + elment + ':first').insertAfter($('#' + ID + ' .' + elment + ':last'));
            $('#' + ID + ' .' + elment + '').eq(pfnum).addClass('active').animate({
                width: '' + pre + '%',
                left: '' + (100 - pre) / 2 + '%',
                top: 0
            }).css({'z-index': number}).find('' + title + '').show();
            $('#' + ID + ' .' + elment + '').eq(pfnum).siblings().removeClass('active').find('' + title + '').hide();
            for (i = 1, th = pfnum; i < pfnum + 1; i++) {

                $('#' + ID + ' .' + elment + '').eq(th + i).animate({
                    width: '' + (pre - 10 * i) + '%',
                    left: '' + (100 - pre) * 0.5 / pfnum * (pfnum - i) + '%',
                    top: '' + 7.5 * i + '%'
                }).css({'z-index': number - i});

                $('#' + ID + ' .' + elment + '').eq(th - i).animate({
                    width: '' + (pre - 10 * i) + '%',
                    left: '' + 100 - (pre - 10 * i) - (100 - pre) * 0.5 / pfnum * (pfnum - i) + '%',
                    top: '' + 7.5 * i + '%'
                }).css({'z-index': number - i});
            }
            ;
            for (i = number; i < len - 1; i++) {
                $('#' + ID + ' .' + elment + '').eq(i).animate({
                    width: '0%',
                    left: '50%',
                    top: '50%'
                }).css({'z-index': 0});
            }
        } else {}
    });

    _BtnRight.hover(function () {
        clearInterval(t);
    }, function () {
        t = setInterval(car, 4000);
    }).click(function () {
        if (new Date - time > 500) {
            time = new Date;
            $('#' + ID + ' .' + elment + ':last').animate({
                width: '' + (pre - 10 * pfnum) + '%',
                left: '' + 100 - (pre - 10 * pfnum) + '%',
                top: '' + 7.5 * pfnum + '%'
            }).css({'z-index': number - pfnum});
            $('#' + ID + ' .' + elment + ':last').insertBefore($('#' + ID + ' .' + elment + ':first'));
            //$("#jzt .list").eq(pfnum).addClass('active');
            $('#' + ID + ' .' + elment + '').eq(pfnum).addClass('active').animate({
                width: '' + pre + '%',
                left: '' + (100 - pre) / 2 + '%',
                top: 0
            }).css({'z-index': number}).find('' + title + '').show();
            $('#' + ID + ' .' + elment + '').eq(pfnum).siblings().removeClass('active').find('' + title + '').hide();
            for (i = 1, th = pfnum; i < pfnum + 1; i++) {

                $('#' + ID + ' .' + elment + '').eq(th + i).animate({
                    width: '' + (pre - 10 * i) + '%',
                    left: '' + (100 - pre) * 0.5 / pfnum * (pfnum - i) + '%',
                    top: '' + 7.5 * i + '%'
                }).css({'z-index': number - i});

                $('#' + ID + ' .' + elment + '').eq(th - i).animate({
                    width: '' + (pre - 10 * i) + '%',
                    left: '' + 100 - (pre - 10 * i) - (100 - pre) * 0.5 / pfnum * (pfnum - i) + '%',
                    top: '' + 7.5 * i + '%'
                }).css({'z-index': number - i});

            }
            for (i = number; i < len - 1; i++) {
                $('#' + ID + ' .' + elment + '').eq(i).animate({
                    width: '0%',
                    left: '50%',
                    top: '5%'
                }).css({'z-index': 0});
            }
        }
    });

    function car() {
        $('#' + ID + ' .' + elment + ':first').animate({width: '30%', left: '35%', top: '5%'}).css({'z-index': 0});
        $('#' + ID + ' .' + elment + ':first').insertAfter($('#' + ID + ' .' + elment + ':last'));
        //$("#jzt .list").eq(2).addClass('active');
        $('#' + ID + ' .' + elment + '').eq(pfnum).addClass('active').animate({
            width: '' + pre + '%',
            left: '' + (100 - pre) / 2 + '%',
            top: 0
        }).css({'z-index': number}).find('' + title + '').show();
        $('#' + ID + ' .' + elment + '').eq(pfnum).siblings().removeClass('active').find('' + title + '').hide();
        for (i = 1, th = pfnum; i < pfnum + 1; i++) {

            $('#' + ID + ' .' + elment + '').eq(th + i).animate({
                width: '' + (pre - 10 * i) + '%',
                left: '' + (100 - pre) * 0.5 / pfnum * (pfnum - i) + '%',
                top: '' + 7.5 * i + '%'
            }).css({'z-index': number - i});

            $('#' + ID + ' .' + elment + '').eq(th - i).animate({
                width: '' + (pre - 10 * i) + '%',
                left: '' + 100 - (pre - 10 * i) - (100 - pre) * 0.5 / pfnum * (pfnum - i) + '%',
                top: '' + 7.5 * i + '%'
            }).css({'z-index': number - i});
        }
        for (i = number; i < len - 1; i++) {
            $('#' + ID + ' .' + elment + '').eq(i).animate({width: '0%', left: '50%', top: '50%'}).css({'z-index': 0});
        }
    }
    var t = setInterval(car, speed);
}
