(function($){
	var $timelines;
	var maxCount = 9;
	var minCount = 0;
	var count = 1;
	var texts = [];
	var timer;
	var delay = 7000;
	
	$(function(){
			   
	$timelines = $('#timeline ul');
	
		$('#timeline li').each(function(e){
			texts.push($(this).attr('title'));
		});
	
		$('#next img')
			.hover( function(){ $(this).css('cursor','pointer'); } )
			.click( nextLine );
	
		$('#pre img')
			.hover( function(){ $(this).css('cursor','pointer'); } )
			.click( preLine );
		
		setTimer();
	})
	
	var setTimer = function(){
		timer = setTimeout(doTimer, delay);
	};
	
	var doTimer = function(){
		nextLine();
		
		if( timer ){ stopTimer(); }
		setTimer();
	};
	
	var stopTimer = function(){
		clearTimeout(timer);
	};
	
	var nextLine = function(){
		if( count < maxCount+1 ){
			count++;
			$timelines.animate(
				{ left: count*-565 + 'px' },
				{ 
					duration: "normal",
					complete: function(){
						if( count === maxCount+1 ){
							count = minCount;
							$timelines.css("left", count*-565 + 'px');
						}
						
					}
				}
			);
		}
	};
	
	var preLine = function(){
		if( count > minCount-1 ){
			count--;
			$timelines.animate(
				{ left: count*-565 + 'px' },
				{ 
					duration: "normal",
					complete: function(){
						if( count === minCount ){
							count = maxCount+1;
							$timelines.css("left", count*-565 + 'px');
						}
						
					}
				}
			);
		}
	};
	
})(jQuery);

