$(function(){
	//在这里加入初始化设置
	//定义图片宽度，单位px
	var slideWidth = 472;
	//定义图片高度，单位px
	var slideHeight = 150;
	//定义滑动方向，默认为左右滑动(leftright)，也可以自定义为上下（updown)
	var direction = 'leftright';
	//定义动画间隔时间，1秒=1000
	var turnSpan = 3000;

	var currentPosition = 0;
	var slides = $('#slidesContainer .slide');
	var numberOfSlides = slides.length;
	var moveLen = 0;
	$('#slidesContainer').css('overflow', 'hidden');
	//slides.before('<div class="focus_tx"></div>');
	slides.wrapAll('<div id="slideInner"></div>');
	$('#slideInner').after('<div class="focus_tx"></div>');
	if(direction == 'leftright'){
		moveLen = slideWidth;
		slides.css({'float':'left','width':slideWidth});
		$('#slideInner').css('width', slideWidth * numberOfSlides);
	}
	if(direction == 'updown'){
		moveLen = slideHeight;
		slides.css({'height':slideHeight});
		$('#slideInner').css('height', slideHeight * numberOfSlides);
	}
	addBtn();
	$('.focus_tx').css({opacity: 0.6});
	$('.slide span').hide().first(0).show();
	var focusInt = setInterval('autoTurn('+moveLen+',\''+direction+'\')',turnSpan);
	$('#focus_btn span').mouseover(function(){
		imageTurn($(this).index(),moveLen,direction);
		clearInterval(focusInt);
	});
	$('#focus_btn span,#slidesContainer .slide').mouseout(function(){
		focusInt = setInterval('autoTurn('+moveLen+',\''+direction+'\')',turnSpan);
	});
	$('#slidesContainer .slide').mouseover(function(){
		clearInterval(focusInt);
	});
});
function addBtn() {
	if(!$('#slidesContainer')) return;
	var focusList = $('#slidesContainer .slide');
	if(!focusList||focusList.length==0) return;
	var SpanBox ='<div id="focus_btn">';
	for(var i=1; i<=focusList.length; i++ ) {
		var spanList ='';
		spanList = '<span class="normal">'+i+'</span>';
		SpanBox += spanList;
	}
	SpanBox += '</div>';
	$('#slidesContainer').append(SpanBox);
	$('#focus_btn span').first(0).removeClass('normal');
	$('#focus_btn span').first(0).addClass('current');
}
function imageTurn(toPosition,moveLen,direction){
	if(direction == 'leftright')
		$('#slideInner').animate({'marginLeft' : moveLen*(-toPosition)});
	else
		$('#slideInner').animate({'marginTop' : moveLen*(-toPosition)});
	$('#focus_btn span').each(function(i){
		if(i == toPosition){
			$(this).removeClass('normal');
			$(this).css({opacity: 0.0});
        	$(this).addClass('current');
			$(this).animate({opacity: 1.0}, 1000);
		}else{
			$(this).removeClass('current');
			$(this).addClass('normal');
		}
	});
	$('.slide span').each(function(i){
		if(i == toPosition){
			$(this).show();
		}else{
			$(this).hide();
		}
		
	});

}
function autoTurn(moveLen,direction){
	var focusBtnList = $('#focus_btn span');
	var currentKey = $('#focus_btn span.current').index();
	var nextKey = currentKey + 1;
	if(nextKey>=focusBtnList.length)
		nextKey = 0;
	imageTurn(nextKey,moveLen,direction);
}
