$(document).ready(function(){
	var currentWline=0;
	var oldWline=0;
	var imgLine=$('#img').find('img').length;
	var bannerW=$('.banner').width();
	var pause;
	var rotateInProgress=false;
	var roimgHover=false;
	$('#img').find('img').css({'position':'absolute','z-index':1}).hide().eq(0).show();
	
	var rollBanner=function(){
		if(!rotateInProgress){
			pause=false;
			currentWline=(oldWline+1)%imgLine;
			$('#banner1Text').find('a').hide().eq(currentWline).fadeIn('slow');
			$('#img').find('img').eq(oldWline).css('z-index','1').fadeOut('slow');
			$('#imgSmall').find('.showSmallimgage').removeClass('select').eq(currentWline).addClass('select');
			$('#img').find('img').eq(currentWline).css('z-index','2').fadeIn('slow',function(){
				rotateInProgress=false;
				if(!pause){
					pause=setTimeout(rollBanner,2000);
				}
			});
			oldWline=currentWline;
		}
	}
	if(!pause){pause=setTimeout(rollBanner,2000);}
	
	$('#imgSmall').find('img').each(function(index){
		$(this).hover(function(){
				clearTimeout(pause);
				imgHover(index);
			},function(){
				if(!pause){pause=setTimeout(rollBanner,1000);}
		});
	});
	$('#imgSmall').find('.prev').click(function(){
		currentWline-=1;
		currentWline<0?currentWline=3:currentWline=currentWline;
		clearTimeout(pause);
		imgHover(currentWline);
		return false;
	}).mouseout(function(){
		if(!pause){pause=setTimeout(rollBanner,1000);}
	});
	$('#imgSmall').find('.next').click(function(){
		currentWline+=1;
		currentWline>3?currentWline=0:currentWline=currentWline;
		clearTimeout(pause);
		imgHover(currentWline);
		return false;
	}).mouseout(function(){
		if(!pause){pause=setTimeout(rollBanner,1000);}
	});

	function imgHover(currentWline){
		if(oldWline!=currentWline){
			$('#banner1Text').find('a').hide().eq(currentWline).fadeIn('slow');
			$('#img').find('img').eq(oldWline).css('z-index','1').fadeOut('slow');
			$('#imgSmall').find('.showSmallimgage').removeClass('select').eq(currentWline).addClass('select');
			$('#img').find('img').eq(currentWline).css('z-index','2').fadeIn('slow');
			oldWline=currentWline;
			pause=false;
		}
	}
	
	var imgNum=$('#pptImg').find('img').length;
	var pptImgW=$('#pptImg').find('img').width();
	var oldpptImg=0;
	var currentpptImg=0;
	var rollppt=false;
	var pausePPT=false;
	$('#pptImg').find('a').eq(0).css('left',0);
	$('#pptText').find('a').eq(0).css('left',0);
	$('#cursor').find('a').eq(0).addClass('select');
	
	var roppt=function(){
		if(!pausePPT){
			pausePPT=true;
			currentpptImg=(oldpptImg+1)%imgNum;
			$('#pptText').find('a').eq(oldpptImg).animate({'left':-pptImgW},1000,function(){
				$('#pptText').find('a').css('left',pptImgW);
			});
			$('#pptText').find('a').eq(currentpptImg).animate({left:0},1000);
			$('#cursor').find('a').removeClass('select').eq(currentpptImg).addClass('select');
			$('#pptImg').find('a').eq(oldpptImg).animate({left:-pptImgW},1000,function(){
				$('#pptImg').find('a').css('left',pptImgW);
			});
			$('#pptImg').find('a').eq(currentpptImg).animate({left:0},1000,function(){
				pausePPT=false;
				if(!pausePPT){	rollppt=setTimeout(roppt,3000);}
			});
			oldpptImg=currentpptImg;	
		}
	}
	rollppt=setTimeout(roppt,3000);
	
	$('#cursor').find('a').each(function(index){
		$(this).hover(function(){
			clearTimeout(rollppt);
			currentpptImg=index;
			if(currentpptImg!=oldpptImg){
				if(!pausePPT){
					pausePPT=true;
					$('#pptText').find('a').eq(oldpptImg).animate({'left':-pptImgW},200,function(){
						$('#pptText').find('a').css('left',pptImgW);
					});
					$('#pptText').find('a').eq(currentpptImg).animate({left:0},200);
					$('#cursor').find('a').removeClass('select').eq(currentpptImg).addClass('select');
					$('#pptImg').find('a').eq(oldpptImg).animate({left:-pptImgW},200,function(){
						$('#pptImg').find('a').css('left',pptImgW);
						pausePPT=false;
					});
					$('#pptImg').find('a').eq(currentpptImg).animate({left:0},200);
					oldpptImg=currentpptImg;	
				}
			}
		},function(){
			if(!pausePPT){	rollppt=setTimeout(roppt,3000);}
		})
	});
});
