
$(function() {
	$('#dowebok').easyFader();
});

window.onload = function() {

}
$(function(){
	nav_resize();
	add_img_bg();
	// setTimeout("add_img_bg()",20);
	footer_ewm();
	gotop();
	

});



// 主要我是本人封装的常用函数库，转载请注明来自酹江月
// 获取ID
function $id(id) {return document.getElementById(id);}


// 检查是否为PC,PC时返回true；
function is_pc() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone","iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}
 

//返回顶部
function gotop() {
    var goTop = $id("gotop");
    goTop.onmouseover=function(){
        goTop.style.opacity='1';
    }
    goTop.onmouseout=function(){
        goTop.style.opacity='0.6';
    }

    window.onscroll = function() {
        if (scroll().top>10) {
            open1(goTop);
            if (scroll().top>200) goTop.style.opacity='0.6';
        }
        else{
            close1(goTop);
        }
        // 如果大于0 就显示 否则隐藏
        leader = scroll().top; // 把 卷去的头部 给  起始位置
        // console.log(scroll().top);
    }
    var leader = 0,
        target = 0,
        timer = null;
    // leader 起始位置  target  目标位置
    goTop.onclick = function() {
        target = 0; //  点击完毕之后 奔向0 去的  不写也可以
        timer = setInterval(function() {
            leader = leader + (target - leader) / 10;
            window.scrollTo(0, leader); // 去往页面中的某个位置
            if (leader == target) {
                clearInterval(timer);
            }
        }, 20);
    }
}

// 导航效果
function nav_resize() {
    $.each($(".nav2"),function(){//隐藏没有下拉子菜单的btn2；
        if($(this).find("li,dl").length==0)$(this).siblings(".btn2").hide();
    });
    re_size(); //先执行一次
    var start_w="",end_w="";//移动前宽度，移动后宽度
    client().width>767?start_w="pc":start_w="mobile";//判断浏览器宽度
    window.onresize =throttle(function(){//调用闭包节流函数
        client().width>767?end_w="pc":end_w="mobile";//判断浏览器宽度
        if (start_w!=end_w) {//判断是否大于767，执行函数
            re_size();
            start_w=end_w;  //把移动后的值赋给移动前，以便下次使用。
        }
    });
    function re_size(){
            var n1 = false; //记录按钮1的开关状态；
        if (client().width <= 767) {
            $("#btn1").find("i").attr("class", "icon-reorder");//初始化样式
            $("#nav1").removeAttr("style");//初始化样式
            $(".btn2").removeClass('rotate180');//初始化样式
            $(".nav2").removeAttr("style");//初始化样式
            $("#btn1").click(function() {//给按钮1绑定事件
                if (n1 == true) {
                    $(this).find("i").attr("class", "icon-reorder")
                    n1 = false;
                } else {
                    $(this).find("i").attr("class", "icon-remove")
                    n1 = true;
                }
                $("#nav1").stop().slideToggle(300);
            });
            var that;//记录上次点击的对象
            $(".btn2").click(function() {//给按钮2绑定事件
                // var that=this;
                if (that!=this){//判断是否和上次点击的对象相同，相同则不执行这个方法
                    $(".btn2").parent().siblings().find(".btn2").removeClass('rotate180');
                    $(".nav2").parent().siblings().find(".nav2").slideUp(300);
                }
                that=this;
                $(this).toggleClass('rotate180');
                $(this).siblings(".nav2").slideToggle(300);
                
            });
        } else {
            $("#nav1").removeAttr("style");//初始化样式
            $(".nav2").removeAttr("style");//初始化样式
        }
    }
}


//获取屏幕可视宽度高度，
function client() {
    if (window.innerWidth != null) // ie9 +  最新浏览器
    {
        return {
            width: window.innerWidth,
            height: window.innerHeight
        }
    } else if (document.compatMode === "CSS1Compat") // 标准浏览器
    {
        return {
            width: document.documentElement.clientWidth,
            height: document.documentElement.clientHeight
        }
    }
    return { // 怪异浏览器
        width: document.body.clientWidth,
        height: document.body.clientHeight
    }
}

// 闭包节流
function throttle(fn,timeout) {  // 闭包  节流
    var timeout= timeout||300;
   var timer = null;
   return function() {
       clearTimeout(timer);
       timer = setTimeout(fn,timeout);
   }
}




