 $(function(){
    function initBox() {
        if (w_width > 861) {
            $('.banner').css({
                height: w_height - $hdh
            });
            $('.bannerSlide .item').css({
                height: w_height - $hdh
            });
            setImgMax($('.banner .pic'), 1880, 968, w_width, w_height - $hdh);
            //$('.wsqh').css({height:w_height});
        } else {
            $('.banner').css({
                height: "auto"
            });
            $('.bannerSlide .item').css({
                height: "auto"
            });
            $('.bannerSlide .pic').attr("style", "");
        }
    };
    initBox();
    $(window).resize(function() {
        initBox();
    });
    if (w_width > 861) {
        var anum = $('.banner .item').length;
        if (anum > 0 && anum < 10) {
            $('.banum .anum').html('0' + anum);
        } else {
            $('.banum .anum').html(anum);
        }
        $('.bannerSlide').bxSlider({
            auto: true,
            pause: 5000,
            mode: "fade",
            pager: true,
            controls: true,
            nextText: '',
            prevText: '',
            onSliderLoad: function(currentIndex) {
                $('.banner .pic').eq(currentIndex).addClass("imgIn");
                var cnum = currentIndex + 1;
                if (cnum > 0 && cnum < 10) {
                    $('.banum .cnum').html('0' + cnum);
                } else {
                    $('.banum .cnum').html(cnum);
                }
                $('.bannerTxts').eq(currentIndex).addClass('show');
            },
            onSlideAfter: function($slideElement, oldIndex, newIndex) {
                $('.banner .pic').removeClass("imgIn").eq(newIndex).addClass("imgIn");
                var cnum = newIndex + 1;
                if (cnum > 0 && cnum < 10) {
                    $('.banum .cnum').html('0' + cnum);
                } else {
                    $('.banum .cnum').html(cnum);
                }
                $('.bannerTxts').removeClass('show');
                $('.bannerTxts').eq(newIndex).addClass('show');
            }
        });
    } else {
        $('.bannerSlide').bxSlider({
            auto: true,
            controls: false,
            pager: true,
            pause: 5000
        });
    };
  });
var isTouch = Modernizr.touch, 
	isMobile = false,//区分移动端与PC端
	mobile = false,//区分手机端与平板
	w_width =  0,
	w_height = 0,
	$mtoph = 0,
	ST = 0,
	navItem = 0,
	$menuBtn=$('.menu-handler'),
	$menuBox=$(".menuBox"),
	pbaH = 0;
	
//移动端事件和PC事件的切换	
var _mousemove;
var _click;
var _mousedown;
var _mouseup;
if (Modernizr.touch) {
    _mousemove = "touchmove";
    _click = "touchend";
    _mousedown = "touchstart";
    _mouseup = "touchend";
} else {
    _mousemove = "mousemove";
    _click = "click";
    _mousedown = "mousedown";
    _mouseup = "mouseup";
}; 

function pageBox() {
   	w_width = $(window).width();
    w_height = $(window).height();	
	$hdh = $('.header').innerHeight();
	$mtoph = $('.mtop').height();
	
    if (w_width <= 1024) {
        isMobile = true;
    } else if (w_width > 1024) {
        isMobile = false;
    };
    if (w_width <= 640) {
        mobile = true;
    } else if (w_width > 640) {
        mobile = false;
    };
	if( w_width > 1152 ){
		pbaH = $hdh;
	}else{
		pbaH = $mtoph;
	}
};
pageBox();
$(window).resize(function () {
    pageBox();
});
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 stcur = $(this);
			var stDD = $(this).parents("p").parents("dd");
			if (stDD.find(".msubnav").size() > 0) {
				if (stcur.hasClass("cur")) {
					stDD.find(".msubnav").stop(false, false).slideUp();
					stcur.removeClass("cur");
				} else {
					jQuery(".navMobile dd p a").removeClass("cur");
					jQuery(".msubnav").stop(false, false).slideUp();
					stDD.find(".msubnav").stop(false, false).slideDown();
					stcur.addClass("cur");
					e.preventDefault();
				}
			}
		});
		$(document).on("click", "#bg-santai", menu.open)
	},
	open: function () {
		if ($("body").is(".open")) {
			$("body").removeClass("open");
			$(".menu-handler").removeClass("active");
			$("#bg-santai").fadeTo("fast", 0, function () {
				$("#bg-santai").hide();
			});
		} else {
			$("#bg-santai").fadeTo("fast", 0.4);
			$("body").addClass("open");
			$(".menu-handler").addClass("active");
		}
	}
};
$(function () {
	$(window).scroll(function () {
		ST = $(window).scrollTop();
		if (ST < w_height&&$('.pbanner').size()!=0&&!isMobile) {
			$('.pbanner .pic').css('transform',"translate(0px,"+(ST) / 1.5+"px)");
		}
		changeHeader();
    });
	
	//pc nav
	$('.nav li').mouseenter(function(){
		if($(this).find('.tnavbox').size()!=0){
			$(this).find('.tnavbox').addClass('show');
		}
	}).mouseleave(function(){
		if($(this).find('.tnavbox').size()!=0){
			$(this).find('.tnavbox').removeClass('show');
		}
	});

	if($('.pbanner').length>=1){
    	setTimeout(function() {
	    	$('.pbanner').addClass('trans-1');
	    	$('.pbanner').removeClass('picw');
	    }, 100);
	    setTimeout(function() {
	      $('.pbanner').removeClass('trans-1');
	    }, 600);
    };
    
	if(w_width>1153){
		$('.menu-handler').bind(_click, function(){
			if (navItem == 0) {
				$(this).addClass('active');
				$('.htnavbox').addClass('showNav');
				navItem = 1;
			}else{
				$(this).removeClass('active');
				$('.htnavbox').removeClass('showNav');
				navItem = 0;
			};
		});
	}else{
		menu.init();
	}
	
	
	function changeHeader(){
		if($('.header2').size()!=0&&!isMobile){
			ST = $(window).scrollTop();
			if(ST > $hdh){
				$('.header2').addClass('show');
			}else{
				$('.header2').removeClass('show');
			}
		}
	};
	changeHeader();
	
	$('.bamouse').click(function(){
		$("html,body").animate({scrollTop:w_height},800,"easeInOutExpo");
	});

	
	
});


// wow.js
if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))){
    new WOW().init();
};

