
//search
$(document).ready(function(){
	$('.keyword').focus(function(){
		this.value="";
	});
});

//news
$(document).ready(function(){
	//设置翻转变量
	var inProgress=false;
	var current=0,old=0;
	var hiddenPosition=$('.news ul').height();
	var count=$('.news ul> li').length;
	var timeout;
	var inProgress=false;
	$('.news ul > li').css('top',hiddenPosition);
	$('.news ul > li:eq('+current+')').css('top','0');
	//执行翻转
	
	var rotate=function(){
		if(!inProgress){
			inProgress=true;
			timeout=false;
			current= (old+1) % count;
			$('.news ul > li:eq('+old+')')
			.animate({top:-hiddenPosition},'slow',function(){
				$(this).css('top',hiddenPosition);
			});	
			$('.news ul> li:eq('+current+')')
			.animate({top:0},'slow',function(){
				inProgress=false;
				if(!timeout){
					timeout=setTimeout(rotate,3000);
				}
			});
			old=current;
		}
	};
	timeout=setTimeout(rotate,3000);
	//鼠标on暂停
	$('.news .wrapper').hover(
			function(){
				clearTimeout(timeout);
				timeout=false;
			},
			function(){
				if(!timeout){
					timeout=setTimeout(rotate,250);
				}
			}
	);
	//设置按钮功能
	$('.news .button a.next').click(function(){
					clearTimeout(timeout);
				    timeout=false;
					rotateClick();
					return false;
				});
	$('.news .button a.pre').click(function(){
					rotateClickBack();
					return false;
				});
	var rotateClick=function(){
		if(!inProgress){
			inProgress=true;
			timeout=false;
			current= (old+1) % count;
			$('.news ul > li:eq('+old+')')
			.animate({top:-hiddenPosition},'slow',function(){
				$(this).css('top',hiddenPosition);
			});	
			$('.news ul> li:eq('+current+')')
			.animate({top:0},'slow',function(){
				inProgress=false;
			});
			old=current;
		}
	};
	var rotateClickBack=function(){
		if(!inProgress){
			inProgress=true;
			timeout=false;
			if(old>0){
				current= old-1;
			}
			else {
				current=count-1;
			}
			$('.news ul > li:eq('+old+')')
			.animate({top:hiddenPosition},'slow',function(){
				$(this).css('top',hiddenPosition);
			});	
			$('.news ul> li:eq('+current+')')
			.css('top',-hiddenPosition)
			.animate({top:0},'slow',function(){
				inProgress=false;
			});
			old=current;
		}
	};
	
//
});

//bannerFlash
$(document).ready(function(){
	//设置翻转变量
	var inProgress=false;
	var current=0,old=0;
	var hiddenPosition=$('.imgWrapper > a').height();
	var count=$('.imgWrapper > a').length;
	var totalHeight=count*hiddenPosition;
	var movePosition;
	var timeout;
	var change;
	var inProgress=false;
	var nowon=false;
	//执行翻转
	
	var autoPlay=function(){
		timeout=false;
		current= (old+1) % count;
		movePosition=current*hiddenPosition;
		$('.bannerList li> a').removeClass('current');
		$('.bannerList li> a:eq('+current+')').addClass('current');
		$('.imgWrapper')
		.animate({top:-movePosition},'normal',function(){
													   
				if(!timeout){
				timeout=setTimeout(autoPlay,3000);
				}
				
		});
		old=current;
	};
		timeout=setTimeout(autoPlay,3000);
//暂停 切换图片
	$('.imgWrapper > a').hover(
		function(){
			clearTimeout(timeout);
			timeout=false;
		},
		function(){
			if(!timeout){
			timeout=setTimeout(autoPlay,3000);
			}
		}
	);
	$('.bannerList  a').click(function(){
		return false;
	}
	 );
	$('.bannerList  a').hover(function(){
			
			clearTimeout(timeout);
			timeout=false;	   
			var $this=$(this);
			$this.click(function(){
				if(!nowon){
					nowon=true;
					if(!inProgress){
						inProgresss=true;
						change=parseInt(this.name.slice(-1));
						movePosition=change*hiddenPosition;
						$('.imgWrapper')
						.animate({top:-movePosition},'fast',function(){
							nowon=false;
						});
						$('.bannerList li> a').removeClass('current');
						$('.bannerList li> a:eq('+change+')').addClass('current');
						clearTimeout(timeout);
						timeout=false;	
						old=change;
						return false;
						inProgress=false;
					}
				}
			}
			);
		},
		function(){
			var $this=$(this);
			$this.click(function(){
			}
			);
			if(!timeout){
			timeout=setTimeout(autoPlay,3000);
			}	
		}
	);
										
});