// JavaScript Document By Trance

$(document).ready(function(){
						   
var t=false; //��ʱ��
var time=4000; //�л����
var speed=500; //��ʱ��
var fot=300; //����ʱ��
var fin=300; //����ʱ��
var i=0; //��ʼ����						   
var len=$("#list_index li").length; //�����ݸ���
var wh=310; //ÿ������ݵĿ��

$("#info_index").css({"width": wh*len + "px"});
//��ǵ�ǰ					   
function cur(ele,currentClass){
	ele= $(ele)? $(ele):ele;
	ele.addClass(currentClass).siblings().removeClass(currentClass);
	}
	
	$("#prev").click(function(){			
		roll(-1);		
		})
    
	$("#next").click(function(){			
		roll(1);		
		})	
	
	$("#list_index li").mouseover(function(){
		checkfade();
		i=$("#list_index li").index($(this)[0]);	
		if(!$(this).hasClass("cur")){
			fade(i);
			}		
		cur(this,"cur");		
		})
	//�����
	function roll(j){
		checkroll();
		if(!$("#info_index").is(":animated")){
			i+=j;					
			if(i!=-1 && i!=len){						
				$("#info_index").animate({"left" : -(wh*i)+"px"},speed);
				//cur($("#list li").eq(i) , "cur");						
				}else if(i==-1){
					i=len-1;
					$("#info_index").css({"left" : -(wh*(i-1))+"px"});
					$("#info_index").animate({"left" : -(wh*i)+"px"},speed);
					//cur($("#list li").eq(i) , "cur");
					}else if(i==len){								
						i=0;
						$("#info_index").css({"left" : -wh+"px"});
						$("#info_index").animate({"left" : 0+"px"},speed);						
						}	
			cur($("#list_index li").eq(i) , "cur");			
			}			
		}
		
	//Fade ����
	function fade(k){
		checkfade();
		$("#info_index").find("div:visible").fadeOut(fot,function(){
			$("#info_index").find("div").eq(k).fadeIn(fin)
			})
		}
		
	//��鲢�ҳ�ʼ����
	function checkroll(){		
		if($("#info_index").find(".hide").html()){
			//alert("ִ���� checkroll ����"+index);
			$("#info_index").find("div").removeClass("hide").show();
			$("#info_index").css({"left" : -(wh*i)+"px"});
			}
		}
	//��鲢�ҳ�ʼ��Fade	
	function checkfade(){
		if(!$("#info_index").find(".hide").html()){
			//alert("ִ���� checkfade ����");
			$("#info_index").find("div").not($("#info_index").find("div").eq(i)).addClass("hide");
			$("#info_index").css({"left" : 0+"px"});
			}
		}
	
	//�Զ�ִ��
	function setInt(){
		t=setInterval(function(){roll(1)},time);
		}
	function clearInt(){
		if(t) clearInterval(t);
		}
		
	$("#area").hover(
		function(){ clearInt() },
		function(){ setInt() }
		)	
	
	//��Ӧ����
	$(document).keydown(function(event){ 
		event = event || window.event;
		if(event.keyCode==38 || event.keyCode==37){	
			clearInt();
			roll(-1);
			setInt();
			};
		if(event.keyCode==40 || event.keyCode==39){			
			clearInt();
			roll(1);
			setInt();
			};	
		})
	
	//��ʼ�Զ�
	setInt();	
	
	})