// JavaScript Document
$(function (){
	$("#nav li:has('.drop')").hover(
		function(){
			$(this).children(".drop").slideDown("fast");
		},
		function(){
			$(this).children(".drop").slideUp("fast");
		}
	);
	var autoTime=0;
	var clickTime=0;
	var num=0;
	var current=0; 
	var step=876;	
	var changeTime= 500;
	var playTime=4000;
	var allWidth=parseInt($("#pro").width());
	var trueWidth=parseInt($("#box").width());
	var linkObj=$("#bn a");	
	function autoPlay(){
		if(allWidth+current<trueWidth) {
		}else if(allWidth+current==trueWidth){
			current=0;
			num=0
			for(var i=0; i<linkObj.length; i++){
				if(i==num){
					$(linkObj[i]).addClass("hover");
				}else{
					$(linkObj[i]).removeClass("hover");
				}
			}
			$("#pro").animate({left: current}, changeTime);
		}
		else{
		num+=1;
		for(var i=0; i<linkObj.length; i++){
			if(i==num){
				$(linkObj[i]).addClass("hover");
			}else{
				$(linkObj[i]).removeClass("hover");
			}
		}
		current=current-step;
		$("#pro").animate({left: current}, changeTime);
		}
		autoTime=setTimeout(autoPlay,playTime)
	}
	var beginTime=setTimeout(autoPlay,playTime);
	linkObj.click(function(){
		clearTimeout(beginTime);
		clearTimeout(autoTime);
		clearTimeout(clickTime);
		num=$(this).index();
		current=-(num)*step;
		$("#pro").animate({left: current}, changeTime);
		for(var i=0; i<linkObj.length; i++){
			if(i==num){
				$(linkObj[i]).addClass("hover");
			}else{
				$(linkObj[i]).removeClass("hover");
			}
		}
		clickTime=setTimeout(autoPlay,playTime);
	});
	
});
