/**
 * 
 * 开启横杠模式的url
 */
jQuery.extend({
    goToPage: function(page, e) {
        var url = window.location.href;
        if (url.indexOf("-p-") === -1) {
            url=url.replace('.html','-p-'+page+ ".html")
        }
        else {
            var urlArr = url.split("-p-");
            var urlArr2 = url.split(".html");
            var str = '';
            if(urlArr2.length>1){
                 str = urlArr2[1];
            }
            url=urlArr[0]+"-p-"+page+".html" + str;
        }
        window.location.href = url;
    },
    U: function(url) {
//        console.log(url)
        url = url.split("?", 2);
//        console.log(url)
        url[0] = url[0].replace(/\//g, '-');
        var seo_base_link = $("meta[name='seo-base-link']").attr("content");
        if(seo_base_link){
            url[0] = seo_base_link + '-' + url[0];
            var host = window.location.href;
            if(host.indexOf("vip")>=0){
                url[0] = url[0].replace('-','/');
            }
        }else{
            url[0] = '/' + url[0];
        }
        return url.join("?");
    }

});

//最新公告
function noticeRoll() {
     
    $(".notice-box").each(function(i) {
        var count = $(this).find("ul.notice-ul li").length;
        var active = $(this).find("ul.notice-ul").data('notice_active');
        active = isNaN(parseInt(active)) ? 0 : parseInt(active);
        var next = active + 1;
        next = next >= count ? 0 : next;
        $(this).find(" ul.notice-ul").data('notice_active', next);
        var active_obj = $(this).find("ul.notice-ul").find('li').eq(active);
        var next_obj = $(this).find("ul.notice-ul").find('li').eq(next);
        $(active_obj).fadeOut("slow", function() {
            $(next_obj).removeClass("hidden").fadeIn("slow");
        });
    });

}

//留言

$(document).ready(function() {
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        { 
            c_start=c_start + c_name.length+1 
            c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        } 
    }
    return ""
}
//定时记录音乐播放时间
function mt(){
    var audio=document.getElementById("audio");
    var time = audio.duration;
    var timer = null;
    timer = setInterval(function(){
        var currentTime = audio.currentTime;
        if(currentTime < time){
            setCookie("currentTime", currentTime);
        }else{
            audio.play();
            time = audio.duration;
            setCookie("currentTime", currentTime);
        }
    },1000);
}


    //搜索框
    $("form[role='search']").find("ul[role='menu'] li a").on("click", function() {
        var searchInputId = $(this).attr("data-role");
        if(typeof $('#keywords') != 'undefined'){
            if(searchInputId == 'chinaSoSearchUrl' ){
                $('#keywords').attr('name','q');
                $('form[role="search"]').attr('method','GET');
                $('form[role="search"]').attr('target','_blank');
            }else{
                $('#keywords').attr('name','name');
                $('form[role="search"]').attr('method','POST');
                $('form[role="search"]').attr('target','_self');
                
            }
        }

        
        $(this).parents(".btn-search-group").find(".btn-search").html($(this).html());
        $(this).parents("form[role='search']").attr("action", $("#" + searchInputId).val());
    });


    //最新公告
    setInterval("noticeRoll()", 6000);
    //banner转动
    if ($('#myCarousel .carousel-indicators li').length > 0) {
        $('#myCarousel').carousel({
            interval: 5000
        })
    }
    //详情页图片滚动
    if ($('#ProductimgBox').length > 0) {
        var ProductUlW = 80 * $('.ProductimgSmall li').length;
        $('.ProductimgSmall ul').css('width', ProductUlW);//给ul宽度
        $('.ProductimgSmall li').on('click', function() {//点击切换大图
            var thisClass = $(this).attr('class');
            $('.ProductimgSmall li').removeClass('active');
            var thisSrc = $(this).find('img').attr('src');
            $(this).addClass('active');
            $('.ProductimgBox li img').attr('src', thisSrc).attr('class', thisClass);
        })

        var ProWidth = $('.ProductimgSmall').width();
        if ($('.ProductimgSmall ul').width() > ProWidth) {//判断有没有下一页
            $('#ProductimgRight').addClass('active');
            $('#ProductimgLeft').addClass('active');
        }
        var liLenght = $('.ProductimgSmall li').length;
        $('#ProductimgRight').on('click', function() {//点击右滚动

            // }//滚动一页
            if (i < liLenght) {
                var Differ = $('.ProductimgSmall ul').width() - $('.ProductimgSmall').width();
                if (-$('.ProductimgSmall ul').position().left <= Differ) {
                    $('.ProductimgSmall ul').animate({left: -80 * i + 5}, 200);
                    i++;
                }
            } else {
                $('.ProductimgSmall ul').animate({left: '5px'}, 200);
                i = 1;
            }
        })
        $('#ProductimgLeft').on('click', function() {//点击左滚动
            // }//滚动一页
            var ProSmaleft = -80 * (i - 1) + 80 + 5 + 'px';
            if (i <= 1) {
                i = 1;
            } else {
                $('.ProductimgSmall ul').animate({left: ProSmaleft}, 200);
                i--;
            }

        })
    }

    var isIE = !!window.ActiveXObject;
    var isIE6 = isIE && !window.XMLHttpRequest;
    var isIE8 = isIE && !!document.documentMode;
    var isIE7 = isIE && !isIE6 && !isIE8;
    if (isIE && isIE6 || isIE7 || isIE8) { //ie判断
        //详情图片点击放大
        $('#clockBig').on('click', function() {
            var thisClass = '.' + $('#clockBig img').attr('class');
            $('#BigImg').css('display', 'block');
            $(".imgBoxTable img").css('display', 'none');
            $(".imgBoxTable " + thisClass + "").css('display', 'block');
            $('#BigImg').addClass('active');
            $(".imgBoxTable " + thisClass + "").addClass('active');
            $('#imgBoxTable img').show();
        });
        //详情图片点击关闭
        $('#closeBigImg').on('click', function() {
            $('#BigImg img').removeClass('active');
            $(".imgBoxTable img").css('display', 'none')
            $('#BigImg').css('display', 'none');
        });

        var imgLength = $('.imgBoxTable img').length;
        var i = 0;
        //下一页
        $('.BigImg .right').on('click', function() {
            var thisData = $(".imgBoxTable .active").attr('data');
            var thisElement = $(".imgBoxTable .active");
            if (thisData < imgLength) {
                $(".imgBoxTable img").removeClass('active')
                $(".imgBoxTable img").css('display', 'none');
                thisElement.next().css('display', 'block').addClass('active');
            }
        })
        //上一页
        $('.BigImg .left').on('click', function() {
            var thisData = $(".imgBoxTable .active").attr('data');
            var thisElement = $(".imgBoxTable .active");
            if (thisData > 0) {
                $(".imgBoxTable img").removeClass('active')
                $(".imgBoxTable img").css('display', 'none');
                thisElement.prev().css('display', 'block').addClass('active');
            }
        })

    } else {
        //详情图片点击放大
        $('#clockBig').on('click', function() {
            var thisClass = '.' + $('#clockBig img').attr('class');
            $('#BigImg').css('display', 'block');
            $(".imgBoxTable img").css('display', 'none');
            $(".imgBoxTable " + thisClass + "").css('display', 'block');
            $('#imgBoxTable img').show();
            setTimeout(function() {
                $('#BigImg').addClass('active');
                $(".imgBoxTable " + thisClass + "").addClass('active');
            }, 50);
        });
        //详情图片点击关闭
        $('#closeBigImg').on('click', function() {
            $('#BigImg img').removeClass('active');
            $(".imgBoxTable img").css('display', 'none')
            setTimeout(function() {
                $('#BigImg').css('display', 'none');
            }, 300);
        });
        var imgLength = $('.imgBoxTable img').length - 1;
        var i = 0;
        //下一页
        $('.BigImg .right').on('click', function() {
            var thisData = $(".imgBoxTable .active").attr('data');
            var thisElement = $(".imgBoxTable .active");
            if (thisData < imgLength) {
                $(".imgBoxTable img").removeClass('active')
                setTimeout(function() {
                    $(".imgBoxTable img").css('display', 'none');
                    thisElement.next().css('display', 'block');
                }, 300);
                setTimeout(function() {
                    thisElement.next().addClass('active');
                }, 350);
            }
            ;
        })
        //上一页
        $('.BigImg .left').on('click', function() {
            var thisData = $(".imgBoxTable .active").attr('data');
            var thisElement = $(".imgBoxTable .active");
            if (thisData > 0) {
                $(".imgBoxTable img").removeClass('active')
                setTimeout(function() {
                    $(".imgBoxTable img").css('display', 'none');
                    thisElement.prev().css('display', 'block');
                }, 300);
                setTimeout(function() {
                    thisElement.prev().addClass('active');
                }, 350);
            }
        })
    }

    /*2级分类展开*/
    if ($('#ProClass').length) {
        $('#ProClass li.ac .first').attr('href', 'javascript:;');
        function clearAll() {
            $('#ProClass li .classBox').css('height', '0');
            $('#ProClass li').removeClass('Selection');
        }
        $('#ProClass li.ac').on('click', function() {
            var liH = $(this).find('.first').height() + 7;
            H = $(this).find('.classBox .classBoxLi').size() * liH,
                    obj = $(this).find('.classBox'),
                    obj2 = $(this);
            if (obj2.hasClass('Selection')) {
                $('#ProClass').removeClass('ac');
                $('#ProClass li .classBox').animate({
                    height: '0'
                }, 300);
                setTimeout(function() {
                    $('#ProClass li').removeClass('Selection');
                }, 300);
            } else {
                $('#ProClass').addClass('ac');
                $('#ProClass .classBox').css('top', liH);
                clearAll();
                obj2.addClass('Selection');
                obj.animate({
                    height: H
                }, 300);
            }
        });
        $('.ProClassBg').on('click', function() {
            $('#ProClass').removeClass('ac');
            $('#ProClass li .classBox').animate({
                height: '0'
            }, 300);
            setTimeout(function() {
                $('#ProClass li').removeClass('Selection');
            }, 300);
        });
    }

    /*2级分类展开left*/
    if ($('#ProClassLeft').length) {
        $(document).ready(function() {
            $('#ProClassLeft li.ac .first').attr('href', 'javascript:;');
            var dd = $('#ProClassLeft li.ac').find('.gg');
            if(dd.hasClass('gg')){
                var thisobj = dd;
                var AH =thisobj.find('a').height();
                var BoxH = thisobj.find('a').length * AH;
                thisobj.animate({height: BoxH}, 500).addClass('ac');
            }
            $('#ProClassLeft li.ac').on('click', function() {
                var thisobj = $(this).find('.classBox');
                var AH = $(this).find('a').height();
                var BoxH = thisobj.find('a').length * AH;
                if (thisobj.hasClass('ac')) {
                    thisobj.parent().find('.first').removeClass('Themebg').removeClass('acc');
                    thisobj.animate({height: '0'}, 500).removeClass('ac');
                    $('#ProClassLeft li').find('.first').removeClass('Themebg').removeClass('acc');
                    $('#ProClassLeft li').find('.classBox').animate({height: '0'}, 500).removeClass('ac');
                   
                } else {
                    $('#ProClassLeft li').find('.first').removeClass('Themebg').removeClass('acc');
                    $('#ProClassLeft li').find('.classBox').animate({height: '0'}, 500).removeClass('ac');
                    thisobj.parent().find('.first').addClass('Themebg').addClass('acc');
                    thisobj.animate({height: BoxH}, 500).addClass('ac');
                }
            })
        })
    }
	
	//内页设计
    if ($('#md_detailProductClass,.two_menu_js').length) {
        $(document).ready(function() {
            $('#md_detailProductClass li.ac .first,.two_menu_js li.ac .first').attr('href', 'javascript:;');
            var dd = $('#md_detailProductClass li.ac,.two_menu_js li.ac').find('.gg');
            if(dd.hasClass('gg')){
                var thisobj = dd;
                var AH =thisobj.find('a').height();
                var BoxH = thisobj.find('a').length * AH;
                thisobj.animate({height: BoxH}, 500).addClass('ac');
            }
            $('#md_detailProductClass li.ac,.two_menu_js li.ac').on('click', function() {
                var thisobj = $(this).find('.classBox');
                var AH = $(this).find('a').height();
                var BoxH = thisobj.find('a').length * AH;
                if (thisobj.hasClass('ac')) {
                    thisobj.parent().find('.first').removeClass('Themebg').removeClass('acc');
                    thisobj.animate({height: '0'}, 500).removeClass('ac');
                } else {
                    thisobj.parent().find('.first').addClass('Themebg').addClass('acc');
                    thisobj.animate({height: BoxH}, 500).addClass('ac');
                }
            })
        })
    }

	// if ($('.two_menu_js').length){
 //        $(document).ready(function() {
 //            $('.two_menu_js li.ac .first').attr('href', 'javascript:;');
 //            var dd = $('.two_menu_js li.ac').find('.gg');
 //            if(dd.hasClass('gg')){
 //                var thisobj = dd;
 //                var AH =thisobj.find('a').height();
 //                var BoxH = thisobj.find('a').length * AH;
 //                thisobj.animate({height: BoxH}, 500).addClass('ac');
 //            }
 //            $('.two_menu_js li.ac').on('click', function() {
 //                var thisobj = $(this).find('.classBox');
 //                var AH = $(this).find('a').height();
 //                var BoxH = thisobj.find('a').length * AH;
 //                if (thisobj.hasClass('ac')) {
 //                    thisobj.parent().find('.first').removeClass('Themebg').removeClass('acc');
 //                    thisobj.animate({height: '0'}, 500).removeClass('ac');
 //                } else {
 //                    thisobj.parent().find('.first').addClass('Themebg').addClass('acc');
 //                    thisobj.animate({height: BoxH}, 500).addClass('ac');
 //                }
 //            })
 //        })
 //    }
	
    $('body').append('<!-- JS储存在User/View/Design/title.html -->' +
        '<div class="common_gototop">' +
        '<img src="/static/index/guandao/image/gototop.png" alt="" />' +
        '</div>');
    $(".common_gototop").click(function() {
        $("html,body").animate({scrollTop: 0}, 1500);
    });
});
//导航二级分类效果
if($('#NavBoxPublic').length){
    function NavBtn(){
        $('#NavBoxPublic').css('height',$(window).height()-56);
        if($('.NavBoxPublic').hasClass('active')){
            $('#NavBoxBg').removeClass('active');
            $('.NavBoxPublic').removeClass('active');
            setTimeout(function(){
                $('#NavBoxBg').hide();
                $('.NavBoxPublic').hide();
            },500);
        }else{
            $('#NavBoxBg').show();
            $('.NavBoxPublic').show();
            setTimeout(function(){
                $('#NavBoxBg').addClass('active');
                $('.NavBoxPublic').addClass('active');
            },50);

        }
    }
    $('#NavBtn').on('click',function(){
        NavBtn();
    });
    $('#NavBoxBg').on('click',function(){
        NavBtn();
    });

    $('#NavBoxPublic .TriangleBtn').on('click',function(){
        var NavBoxli = $(this).parent().find('ul li');
        var H = NavBoxli.size()*NavBoxli.height();
        if($(this).hasClass('active')){
            NavBoxli.parent('ul').css('height','0');
            $(this).removeClass('active');
        }else{
            NavBoxli.parent('ul').css('height',H);
            $(this).addClass('active');
        }
    });
}

/*! Lazy Load 1.9.5 - MIT license - Copyright 2010-2015 Mika Tuupola */
!function(a, b, c, d) {
    var e = a(b);
    a.fn.lazyload = function(f) {
        function g() {
            var b = 0;
            i.each(function() {
                var c = a(this);
                if (!j.skip_invisible || c.is(":visible"))
                    if (a.abovethetop(this, j) || a.leftofbegin(this, j))
                        ;
                    else if (a.belowthefold(this, j) || a.rightoffold(this, j)) {
                        if (++b > j.failure_limit)
                            return!1
                    } else
                        c.trigger("appear"), b = 0
            })
        }
        var h, i = this, j = {threshold: 0, failure_limit: 0, event: "scroll", effect: "show", container: b, data_attribute: "original", skip_invisible: !1, appear: null, load: null, placeholder: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"};
        return f && (d !== f.failurelimit && (f.failure_limit = f.failurelimit, delete f.failurelimit), d !== f.effectspeed && (f.effect_speed = f.effectspeed, delete f.effectspeed), a.extend(j, f)), h = j.container === d || j.container === b ? e : a(j.container), 0 === j.event.indexOf("scroll") && h.bind(j.event, function() {
            return g()
        }), this.each(function() {
            var b = this, c = a(b);
            b.loaded = !1, (c.attr("src") === d || c.attr("src") === !1) && c.is("img") && c.attr("src", j.placeholder), c.one("appear", function() {
                if (!this.loaded) {
                    if (j.appear) {
                        var d = i.length;
                        j.appear.call(b, d, j)
                    }
                    a("<img />").bind("load", function() {
                        var d = c.attr("data-" + j.data_attribute);
                        c.hide(), c.is("img") ? c.attr("src", d) : c.css("background-image", "url('" + d + "')"), c[j.effect](j.effect_speed), b.loaded = !0;
                        var e = a.grep(i, function(a) {
                            return!a.loaded
                        });
                        if (i = a(e), j.load) {
                            var f = i.length;
                            j.load.call(b, f, j)
                        }
                    }).attr("src", c.attr("data-" + j.data_attribute))
                }
            }), 0 !== j.event.indexOf("scroll") && c.bind(j.event, function() {
                b.loaded || c.trigger("appear")
            })
        }), e.bind("resize", function() {
        g()
        }), /(?:iphone|ipod|ipad).*os 5/gi.test(navigator.appVersion) && e.bind("pageshow", function(b) {
            b.originalEvent && b.originalEvent.persisted && i.each(function() {
                a(this).trigger("appear")
            })
        }), a(c).ready(function() {
            g()
        }), this
    }, a.belowthefold = function(c, f) {
        var g;
        return g = f.container === d || f.container === b ? (b.innerHeight ? b.innerHeight : e.height()) + e.scrollTop() : a(f.container).offset().top + a(f.container).height(), g <= a(c).offset().top - f.threshold
    }, a.rightoffold = function(c, f) {
        var g;
        return g = f.container === d || f.container === b ? e.width() + e.scrollLeft() : a(f.container).offset().left + a(f.container).width(), g <= a(c).offset().left - f.threshold
    }, a.abovethetop = function(c, f) {
        var g;
        return g = f.container === d || f.container === b ? e.scrollTop() : a(f.container).offset().top, g >= a(c).offset().top + f.threshold + a(c).height()
    }, a.leftofbegin = function(c, f) {
        var g;
        return g = f.container === d || f.container === b ? e.scrollLeft() : a(f.container).offset().left, g >= a(c).offset().left + f.threshold + a(c).width()
    }, a.inviewport = function(b, c) {
        return!(a.rightoffold(b, c) || a.leftofbegin(b, c) || a.belowthefold(b, c) || a.abovethetop(b, c))
    }, a.extend(a.expr[":"], {"below-the-fold": function(b) {
            return a.belowthefold(b, {threshold: 0})
        }, "above-the-top": function(b) {
            return!a.belowthefold(b, {threshold: 0})
        }, "right-of-screen": function(b) {
            return a.rightoffold(b, {threshold: 0})
        }, "left-of-screen": function(b) {
            return!a.rightoffold(b, {threshold: 0})
        }, "in-viewport": function(b) {
            return a.inviewport(b, {threshold: 0})
        }, "above-the-fold": function(b) {
            return!a.belowthefold(b, {threshold: 0})
        }, "right-of-fold": function(b) {
            return a.rightoffold(b, {threshold: 0})
        }, "left-of-fold": function(b) {
            return!a.rightoffold(b, {threshold: 0})
        }})
}(jQuery, window, document);
/*延迟加载图片js*/



