var isTouch = Modernizr.touchevents,
	isMobile = false,
	w_width = jQuery(window).width(),
	$mtop = jQuery(".mtop");
var menu = {
    trigger: ".menu-handler",
    init: function () {
        menu.bind();
    },
    bind: function () {
        $(document).on("click", menu.trigger, menu.open);
        $(document).on("click", ".navMobile dd p a", function (e) {
            var menucur = $(this);
            var menuDD = $(this).parents("p").parents("dd");
            if (menuDD.find(".msubnav").size() > 0) {
                if (menucur.hasClass("cur")) {
                    menuDD.find(".msubnav").stop(false, false).slideUp();
                    menucur.removeClass("cur");
                } else {
                    jQuery(".navMobile dd p a").removeClass("cur");
                    jQuery(".msubnav").stop(false, false).slideUp();
                    menuDD.find(".msubnav").stop(false, false).slideDown();
                    menucur.addClass("cur");
                    e.preventDefault();
                }
            }
        });

        $(document).on("click", "#bg-menu", menu.open)
    },
    open: function () {
        if ($("body").is(".open")) {
            $("body").removeClass("open");
            $(".menu-handler").removeClass("active");
            $("#bg-menu").fadeTo("fast", 0, function () {
                $("#bg-menu").hide();
            });
        } else {
            $("#bg-menu").fadeTo("fast", 0.4);
            $("body").addClass("open");
            $(".menu-handler").addClass("active");
        }
    }
};
var _mousemove;
var _click;
var _mousedown;
var _mouseup;
if (Modernizr.touchevents) {
    _mousemove = "touchmove";
    _click = "touchend";
    _mousedown = "touchstart";
    _mouseup = "touchend";
} else {
    _mousemove = "mousemove";
    _click = "click";
    _mousedown = "mousedown";
    _mouseup = "mouseup";
};
function pageBox() {
    w_width = jQuery(window).width();
    w_height = jQuery(window).height();
    if (w_width <= 1024) {
        isMobile = true;
    } else if (w_width > 1024) {
        isMobile = false;
        jQuery('.pbanner .pimg').css('transform', "translate(0px,0px)");
    };
    $mtoph = $mtop.height();
};
function setImgMax(img, imgW, imgH, tW, tH) {
    var tWidth = tW || w_width;
    var tHeight = tH || w_height;
    var coe = imgH / imgW;
    var coe2 = tHeight / tWidth;
    if (coe < coe2) {
        var imgWidth = tHeight / coe;
        img.css({ height: tHeight, width: imgWidth, left: -(imgWidth - tWidth) / 2, top: 0 });
    } else {
        var imgHeight = tWidth * coe;
        img.css({ height: imgHeight, width: tWidth, left: 0, top: -(imgHeight - tHeight) / 2 });
    };
};
pageBox();
jQuery(window).resize(function () {
    pageBox();
});
window.onload = function () {
    $('.loadingBg').fadeOut();
    if (jQuery(".teamIbox").length >= 1) {
        jQuery(".teamIbox dd.item a").height(jQuery(".teamIbox dd.item2 img").innerHeight());
        jQuery(".teamIbox dd.item1 a").height(jQuery(".teamIbox dd.item2 img").innerHeight() * 2);
    }
}
$(".searchTxt").keyup(function (event) {
    var keyvalue = event.which;
    var vakes = $(this).val();
    if (keyvalue == 13) {
        if (vakes == '') {
            $(this).focus();
            return;
        }
        window.location = 'search.aspx?keyword=' + encodeURIComponent(vakes);
    }
})
$('.searchBtn').click(function () {
    var vakes = $(".searchTxt").val();
    if (vakes == '') {
        $(".searchTxt").focus();
        return;
    }
    window.location = 'search.aspx?keyword=' + encodeURIComponent(vakes);
});
//点赞
var isajax2 = true;
function praise(id, obj) {
    var isajx = jQuery(obj).attr("isajx");
    if (isajax2 && isajx == "0") {
        jQuery.ajax({
            type: "POST",
            url: "Tools/updatehite.ashx?t=" + Math.random(),
            data: { action: "updatehite", ID: id },
            dataType: "html",
            cache: true,
            beforeSend: function () {
                isajax2 = false;
            },
            success: function (data) {
                var num = jQuery(obj);
                if (data == "true") {
                    num.html(Number(num.html()) + 1).addClass("red");
                    jQuery(obj).attr("isajx", "1");
                }
                else
                    alert('抱歉,提交失败');
                isajax2 = true;
            },
            error: function () {
                alert("请求错误"); isajax2 = true;
            }
        })
    }
    else {
        alert('亲，你已经点赞过了 不要重复咯');
    }
}
jQuery(function () {
    menu.init();
    jQuery(".gropBox .searchTxt").focus(function () {
        jQuery(this).stop(false, false).animate({ width: "130" }, 300);
    });
    jQuery(".gropBox .searchTxt").blur(function () {
        jQuery(this).stop(false, false).animate({ width: "100" }, 300);
    });
    setPopUp(jQuery(".tool .a4"), "官方微信");
    setPopUp(jQuery(".weixin"), "官方微信");
    function setPopUp(obj, title) {
        obj.click(function () {
            var str = '<div class="popUpblack"><div class="popUp"><div class="t">' + title + '<span class="close">关闭</span></div><div class="img"><img src="' + obj.attr("href") + '"/></div></div></div>';
            $("body").append(str);
            jQuery(".popUpblack").fadeIn();
            jQuery(".popUp").animate({ marginTop: "-127" }, 400);
            $(".popUp .close").click(function () {
                $(".popUpblack").remove();
            });
            jQuery(".popUpblack").click(function () { $(".popUpblack").remove(); });
            return false;
        });
    }
    jQuery(".blacKTop").bind("click", function () { jQuery('html, body').stop().animate({ scrollTop: 0 }, 800, 'easeInOutExpo'); });
    jQuery(".tool .a3").mouseenter(function () {
        jQuery(this).find(".con").stop(false, false).animate({ right: 0 });
    }).mouseleave(function () {
        jQuery(this).find(".con").stop(false, false).animate({ right: -126 });
    });
    //pc nav
    jQuery("#nav li").hover(function () {
        if (jQuery(this).find(".subnav").length > 0) {
            $(this).children("a").addClass("hov");
            $(this).children(".subnav").stop(false, false).animate({ "top": "84px", opacity: "show" }, 280);
        };
    }, function () {
        $(this).children("a").removeClass("hov");
        $(this).children(".subnav").stop(false, false).animate({ "top": "92px", opacity: "hide" }, 280);
    });
    jQuery(".msubnav a,.subnav a").click(function () {
        var anchorCur = jQuery(this).attr("href").split("#")[1];
        if (anchorCur && jQuery("#" + anchorCur).length == 1) {
            navItem = 0;
            setScroll("#" + anchorCur);
        }
    });
    function getHash() {
        var hash = location.href.split("#")[1];
        if (hash) {
            jQuery("html,body").animate({ scrollTop: jQuery("#" + hash).offset().top - $mtoph }, 0);
        }
    };
    getHash();
    function setScroll(anchorCur) {
        jQuery("html,body").animate({ scrollTop: jQuery(anchorCur).offset().top - $mtoph }, 800, 'easeInOutExpo');
    };
    var $pbanner = jQuery(".pbanner");
    if ($pbanner.length > 0) {
        $pbanner.addClass("trans-1 pbannerAct");
        setTimeout(function () {
            $pbanner.removeClass('trans-1');
        }, 1300);
    };
    jQuery(window).scroll(function () {
        var scrollVar = $(window).scrollTop();
        $('.pbanner .pbox').css({
            'opacity': (500 - scrollVar) / 500
        });
        if (scrollVar < w_height && !isMobile) {
            jQuery('.pbanner .pimg').css('transform', "translate(0px," + (scrollVar) / 2.5 + "px)");
        };
    });
});


jQuery(function () {
    var bHeight = 0,
    $banner = jQuery('.banner'),
    $bannerPic = $banner.find(".pic"),
    $bannerImg = $banner.find(".pimg"),
    bannersider = jQuery(".bannerBox");
    var box = jQuery(".caseDemo .item"), sketch = $(".caseDemo .item .c2");
    jQuery(window).load(function () {
        jQuery('.target').delay(300).scrollClass();
    });
    function initBox() {
        w_height > 680 && !isMobile ? bHeight = w_height - $mtoph - 110 : bHeight = w_height - $mtoph;
        $banner.css({ height: bHeight });
        $bannerPic.css({ height: bHeight });
        setImgMax($bannerImg, 1920, 764, w_width, bHeight);
        jQuery(".teamIbox dd.item a").height(jQuery(".teamIbox dd.item2 img").innerHeight());
        jQuery(".teamIbox dd.item1 a").height(jQuery(".teamIbox dd.item2 img").innerHeight() * 2);
        if (!isMobile) {
            bannersider.flexslider({
                slideshowSpeed: 5000,
                animationSpeed: 1200,
                directionNav: false,
                pauseOnHover: false,
                pauseOnAction: false,
                start: function () {
                    jQuery(".bannerBox .pic .binbox").hide().css({ left: "55%", opacity: "hide" });
                    jQuery(".bannerBox .flex-active-slide .binbox").stop(false, false).delay(50).animate({ left: "50%", opacity: "show" }, 600);
                },
                before: function () {
                    jQuery(".bannerBox .pic .binbox").hide().css({ left: "55%", opacity: "hide" });
                },
                after: function () {
                    jQuery(".bannerBox .flex-active-slide .binbox").stop(false, false).delay(50).animate({ left: "50%", opacity: "show" }, 600);
                }
            });
            return true;
        } else {
            bannersider.flexslider({
                animation: "slide",
                slideshowSpeed: 5000,
                animationSpeed: 1200,
                directionNav: false,
                pauseOnAction: false,
                start: function () {
                    jQuery(".bannerBox .pic .binbox").hide().css({ left: "55%", opacity: "hide" });
                    jQuery(".bannerBox .flex-active-slide .binbox").stop(false, false).delay(50).animate({ left: "50%", opacity: "show" }, 600);
                },
                before: function () {
                    jQuery(".bannerBox .pic .binbox").hide().css({ left: "55%", opacity: "hide" });
                },
                after: function () {
                    jQuery(".bannerBox .flex-active-slide .binbox").stop(false, false).delay(50).animate({ left: "50%", opacity: "show" }, 600);
                }
            });

            return true;
        }
    };
    box.unbind("mouseenter mouseleave");
    $('.caseDemo').slick({
        autoplay: true,
        speed: 1500,
        slidesToShow: 4,
        slidesToScroll: 1,
        dots: false,
        arrows: true,
        responsive: [
          {
              breakpoint: 1280,
              settings: {
                  slidesToShow: 3
              }
          },
          {
              breakpoint: 1024,
              settings: {
                  slidesToShow: 2
              }
          },
          {
              breakpoint: 640,
              settings: {
                  slidesToShow: 1
              }
          },
        ]
    });
//  $('.aboutType').slick({
//      autoplay: true,
//      speed: 1500,
//      slidesToShow: 5,
//      slidesToScroll: 1,
//      dots: false,
//      arrows: true,
//      responsive: [
//        {
//            breakpoint: 1024,
//            settings: {
//              slidesToShow: 3,
//      		slidesToScroll: 3
//            }
//        },
//        {
//            breakpoint: 640,
//            settings: {
//                slidesToShow: 2,
//      		 slidesToScroll: 2
//            }
//        },
//      ]
//  });
    initBox();
    if (!isMobile) {
        //team 
        $('.teamIbox dd a').bind('mouseenter', function () {
            $(this).find('.filler-top').stop().animate({
                width: '100%',
                left: 0
            }, 600, "easeOutExpo");
            $(this).find('.filler-bottom').stop().animate({
                width: '100%',
                right: 0
            }, 600, "easeOutExpo");
            $(this).find('.filler-left').stop().animate({
                height: '100%',
                left: 0
            }, 600, "easeOutExpo");
            $(this).find('.filler-right').stop().animate({
                height: '100%',
                top: 0
            }, 600, "easeOutExpo");
            var oP = jQuery(this).parent();
            var oS = $(this).siblings('.team-info');
            if (w_width - oP.position().left >= oP.width() * 2 + 2) {
                oS.css({ 'top': oP.position().top, width: (oP.parent().width() / 9) * 2, 'height': Math.round(oP.height()), 'left': oP.position().left + oP.width(), 'right': 'auto' });
            } else {
                oS.css({ 'top': oP.position().top, width: (oP.parent().width() / 9) * 2, 'height': oP.height(), 'right': w_width - oP.position().left, 'left': 'auto', })
            }
            oS.delay(300).stop(false, false).fadeIn();
        }).bind('mouseleave', function () {
            $(this).find('.filler-top').stop().animate({
                width: 0,
                left: $(this).width()
            }, 600, "easeOutExpo");
            $(this).find('.filler-bottom').stop().animate({
                width: 0,
                left: 0
            }, 600, "easeOutExpo");
            $(this).find('.filler-left').stop().animate({
                height: 0,
                left: 0
            }, 600, "easeOutExpo");
            $(this).find('.filler-right').stop().animate({
                height: 0,
                top: 0
            }, 600, "easeOutExpo");
            var oS = $(this).siblings('.team-info');
            oS.stop(false, false).hide();
        });
    } else {
        $('.teamIbox dd a').unbind("mouseenter mouseleave");
    };
    jQuery(window).resize(function () {
        initBox();
    });
    //num scroll
//  var options = {
//      useEasing: true,
//      useGrouping: true,
//      separator: ',',
//      decimal: '.',
//      prefix: '',
//      suffix: ''
//  };
//  var dnum1 = parseInt(jQuery("#count-number1").attr("data-num"));
//  var dnum2 = parseInt(jQuery("#count-number2").attr("data-num"));
//  var dnum3 = parseInt(jQuery("#count-number3").attr("data-num"));
//  var dnum4 = parseInt(jQuery("#count-number4").attr("data-num"));
//  var dnum5 = parseInt(jQuery("#count-number5").attr("data-num"));
//  var demo = new CountUp("count-number1", 0, dnum1, 0, 2.5, options);
//  var demo2 = new CountUp("count-number2", 0, dnum2, 0, 2.5, options);
//  var demo3 = new CountUp("count-number3", 0, dnum3, 0, 2.5, options);
//  var demo4 = new CountUp("count-number4", 0, dnum4, 0, 2.5, options);
//  var demo5 = new CountUp("count-number5", 0, dnum5, 0, 2.5, options);
//  $(window).scroll(function () {
//      if ($(window).scrollTop() >= jQuery(".ibox").offset().top) {
//          demo.start();
//          demo2.start();
//          demo3.start();
//          demo4.start();
//          demo5.start();
//      }
//  });
    jQuery('.inewImg').slick({
        autoplay: true,
        infinite: true,
        speed: 500,
        fade: true,
        cssEase: 'linear'
    });
    jQuery(".list li").bind("mouseenter", function () {
        jQuery(this).siblings("li").removeClass("act");
        jQuery(this).addClass("act");
    });
    jQuery(".inewTab span").click(function () {
        var num = $(this).index();
        jQuery(".inewTab span").removeClass("act");
        $(this).addClass("act");
        $('.inewIcon .list').hide().eq(num).show();
    });
});


$(document).ready(function($) {
	
	// 手机导航
	$('.menuBtn').append('<b></b><b></b><b></b>');
	$('.menuBtn').click(function(event) {
		$(this).toggleClass('open');
		var _winw = $(window).width();
		var _winh = $(window).height();
		if( $(this).hasClass('open') ){
			$('body').addClass('open');
			if( _winw<=959 ){
				$('.nav').stop().slideDown();
			}
		}else{
			$('body').removeClass('open');
			if( _winw<=959 ){
				$('.nav').stop().slideUp();
			}
		}
	});

    // 头部导航
    function myNav(){
        var _top = $(window).scrollTop();
        var _winw = $(window).width();
            if( _winw>959 ){
                $("#hd .hdr").show();
                $('.nav').addClass('nav-pc').removeClass('nav-m').show();
            }else{
                $('.nav').addClass('nav-m').removeClass('nav-pc');
            }
    }
    myNav();
    $(window).resize(function(event) {
        myNav();
    });

    $('.nav-pc li').bind('mouseenter',function() {
        $(this).find('.subBox').stop().fadeIn("fast");
        if( $(this).find('.subBox').length ){
            $(this).addClass('ok');
        }
    });
    $('.nav-pc li').bind('mouseleave',function() {
        $(this).removeClass('ok');
        $(this).find('.subBox').stop().fadeOut("fast");
    });
    $('body,.menuBtn').removeClass('open');

    $('.nav-m .v1').click(function(){
        if( $(this).siblings('.subBox').length ){
            $(this).siblings('.subBox').stop().slideToggle("500");
            return false;
        }
    });

    // 底部导航
    function myFnav(){
        var _winw = $(window).width();
        if( _winw > 959 ){
            $('.f-nav dd').show();
            $('.f-nav').addClass('f-nav-pc').removeClass('f-nav-m');
        }else{
            $('.f-nav dd').hide();
            $('.f-nav').addClass('f-nav-m').removeClass('f-nav-pc');
        }
    }
    myFnav();
    $(window).on('resize',function(){
        myFnav();
    }); 

    $('.f-nav-m dt').click(function(){
        var _pare = $(this).parent('dl');
        _pare.siblings('dl').removeClass('open').find('dd').stop().slideUp();
        _pare.toggleClass('open');
        if( _pare.hasClass('open') ){
            _pare.find('dd').stop().slideDown();
        }else{
            _pare.find('dd').stop().slideUp();
        }
    });

    //侧边栏
    // $(window).scroll(function(){
    //     var _t = $(window).scrollTop();
    //     var _h = $("#bd").offset().top;
    //     if(_t >= 526){
    //         $("#bd").addClass("fixed");
    //     }else{
    //        $("#bd").removeClass("fixed"); 
    //     };
    // });

    //底部快速链接
    $(".fb-cygs").hover(function(){
        $(".fb-cygs .cygs-v").stop().slideDown("fast");
    },function(){
        $(".fb-cygs .cygs-v").stop().slideUp("fast");
    });





    //头部语言选择
    $("#top .lang").hover(function(){
        $(this).find("ul").stop().slideDown();
    },function(){
        $(this).find("ul").stop().slideUp();
    });

    //返回顶部
    $('.topBtn').click(function(){
        $('body,html').animate({
            scrollTop: 0
        }, 500);
        return false;
    });

    // 选项卡 鼠标点击切换
    $(".TAB_CLICK li").click(function(){
      var tab=$(this).parent(".TAB_CLICK");
      var con=tab.attr("id");
      var on=tab.find("li").index(this);
      $(this).addClass('on').siblings(tab.find("li")).removeClass('on');
      $(con).eq(on).show().siblings(con).hide();
    });

    // 选项卡 鼠标经过切换
    $(".TAB li").mousemove(function(){
      var tab=$(this).parent(".TAB");
      var con=tab.attr("id");
      var on=tab.find("li").index(this);
      $(this).addClass('on').siblings(tab.find("li")).removeClass('on');
      $(con).eq(on).show().siblings(con).hide();
    });


    /*发展历程滚动效果*/
    var list2Length = $('.m-list2 li').length;
    function eachList2() {
        var winHeight = $(window).height();
        var scrollHeight = $('body').height();
        var scrollTop = $(window).scrollTop();
        for(var i = 0; i < list2Length; i++) {
            _top = $('.m-list2 li').eq(i).offset().top;
            if(scrollTop + winHeight/2 >= _top) {
                $('.m-list2 li').eq(i).addClass('on show').siblings('li').removeClass('on');
                $('.m-list2 li').eq(i).nextAll('li').removeClass('show');
            } else if(scrollHeight - winHeight <=  scrollTop) {
                $('.m-list2 li:last').addClass('on show').siblings('li').removeClass('on');
            } else if(scrollTop == 0) {
                $('.m-list2 li:first').removeClass('on show').siblings('li').removeClass('on');
            }
        }
    }
    eachList2();
    $(window).scroll(function() {
        eachList2();
    })
    $(window).resize(function() {
        eachList2();
    })
    
    $('.m-list6 li').mousemove(function(){
      var tab=$(this).parent();
      var con=tab.attr("id");
      var on=tab.find("li").index(this);
      $(this).addClass('on').siblings(tab.find("li")).removeClass('on');
      $(con).eq(on).show(0,function() {
        $(this).addClass('on');
      }).siblings(con).hide().removeClass('on');
    });

	$('.m-pop .bg,.m-pop .close').click(function() {
        $('.m-pop').fadeOut('normal');
    })
    $('#js-video').click(function() {
        var _id = $(this).attr('href');
        $(_id).fadeIn("normal");
        $(_id).find('video')[0].play();
    })
    $('#video-pop .bg,#video-pop .close').click(function() {
        _video = $(this).parents('#video-pop').find('video')[0];
        _video.pause();
        _video.currentTime = 0;
    })
	
});














