$(function(){
	
	//头部轮播图
	var r_num = 0;
	function roastingChart(){
		roastingChartChange();
		r_num++;
		if(r_num >= 4){
			r_num = 0;
		}
	}
	
	function roastingChartChange(){
		$(".lSPager_lists").hide();
		$("#lSPager_"+r_num).show();
		$(".lSPager_btn").css({"border":"1px solid rgba(255,255,255,0.3)","background":"rgba(0,0,0,0.3)"});
		$("#page_"+r_num).css({"border":" 1px solid #d0d3d5","background":"#fff"});
		$(".lSPager_pic").hide();
		$("#lSPager_pic_"+r_num).show();
	}
	
	//轮播计时器
	var timer1 = setInterval(roastingChart,2000);
	
	//点击轮播按钮
	$(".lSPager_btn").click(function(){
		clearInterval(timer1);
		num = $(this).index();
		roastingChartChange();
		timer1 = setInterval(roastingChart,2000);
	});
	
	
	//无缝轮播
	var i = 0;
	
	//克隆第一张图片,复制到列表最后
	//var clone = $(".promo_content_pic .promo_content_pic_lists li").first().clone();
	//$(".promo_content_pic .promo_content_pic_lists").append(clone);
    var size = $(".promo_content_pic .promo_content_pic_lists li").size();

    //自动轮播
    var t = setInterval(function () { i++; move();},2000);

    //向左
    $(".promo_content_pic .btn_l").click(function () {
    	clearInterval(t);
        i++;
        move();
        t = setInterval(function () { i++; move();},2000);
    });
    
    //向右
    $(".promo_content_pic .btn_2").click(function () {
    	clearInterval(t);
        i--;
        move();
        t = setInterval(function () { i++; move();},2000);
    });
	
    //移动事件
    var length = $(".promo_content_pic .promo_content_pic_lists li").width();
	$(window).resize(function(){
		length = $(".promo_content_pic .promo_content_pic_lists li").width();
	});
	
    function move() {
        if (i == size) {
            $(".promo_content_pic .promo_content_pic_lists").css({ left: 0 });
            i = 1;
        }
        if (i == -1) {
            $(".promo_content_pic .promo_content_pic_lists").css({ left: -(size - 1) * length });
            i = size - 2;
        }
        $(".promo_content_pic .promo_content_pic_lists").stop().animate({ left: -i * length }, 500);
    }
    
    
    //在线聊天
    $(".narrow_down_f").click(function(){
    	$(".open_chat").hide();
    	$(".close_chat").show();
    });
    
    $(".close_chat").click(function(){
    	$(".close_chat").hide();
    	$(".open_chat").show();
    });
    
    
	//监听滚动条上下移动,头部导航条显示
    var p=0,t=0;
    $(window).scroll(function(e){
        p = $(this).scrollTop();
          
        if(t<=p){//下滚  
          	$(".nav_header1").hide();
			$(".nav_header").hide();
        }else{//上滚  
			if(p == 0){
				$(".nav_header1").show();
				$(".nav_header").hide();
			}else{
				$(".nav_header").show();
				$(".nav_header1").hide();
			}
        }  
        setTimeout(function(){t = p;},0);
    });
    
    
});
