$(function(){
var timer = null;
var offset = 3000;
var index = 0;



//绑定小图
    $('.banner_n img').each(function(i){
		$(this).bind('mouseover', function(){
            if (timer) {clearTimeout(timer);}                
            index=i;
			rechange(index);
            slideImage(index); 
            timer = window.setTimeout(auto, offset);  
            $(this).parent("li").siblings().removeClass("active"); 
			$(this).parent("li").addClass("active");            
            return false;
    	});
	}); 


//绑定左右按钮，点击切换播放前/后图片
    $('.banner_nav .banner_nav_l img').bind('click', function(){
            if (timer){
                clearTimeout(timer);
            }
            index--;
            if (index < 0) index = 2;
            rechange(index);
            slideImage(index);
            timer = window.setTimeout(auto, offset);
    });
	$('.banner_nav .banner_nav_r img').bind('click', function(){
            if (timer){
                clearTimeout(timer);
            }
            index++;
            if (index > 2) index = 0;
            rechange(index);
            slideImage(index);
            timer = window.setTimeout(auto, offset);
    });
	
//大图交替轮换
function slideImage(i){
    $('.banner_pic li').eq(i).siblings().fadeOut(1000);
	$('.banner_pic li').eq(i).fadeIn(1000);
}

//改变小图焦点
function rechange(loop){
    $('.banner_nav li').removeClass('active');
    $(".banner_nav li").eq(loop).addClass('active');
}

//自动播放函数
function auto(){
    
    if (index > 2){
        index = 0;
    }
    rechange(index);
    slideImage(index);
	index++;
    timer = window.setTimeout(auto, offset);
	
}

//初始调用
    auto(); 
});
