	var current_entry = 0;
	var play_timeline = false;
	var max_entries	  = 3;
	
	function onTimeline(action)
	{
		play_timeline = ( action != undefined ) ? action : true;
		
		setTimeout('onPlayTimeline();', 5000);
	}
	
	function onPlayTimeline()
	{
		if( play_timeline )
		{
			onTimelineNext();
			
			setTimeout('onPlayTimeline();', 5000);
		}
	}
	
	function onTimelineNext()
	{
		current_entry++; 
		
		play_timeline = false;
		
		onTimelineEntry(current_entry);
	}

	function onTimelineBack()
	{
		current_entry--;
		
		play_timeline = false;
		
		onTimelineEntry(current_entry);
	}
	
	function onTimelineEntry(pos)
	{
		$('timeline_entry').hide();
		
		if( pos > (max_entries -1) )
		{
			current_entry = 0;
			pos = 0;
		}
			
		
		/**/
		new Ajax.Request('/timeline/ajax/', 
		{
			asynchronous: false,
			method: 'post',
			requestHeaders: {Accept: 'application/json'},
			parameters: { start: pos, set: 1 },
			onSuccess: function(transport, json)
			{  
				var entry = (json[0]) ? json[0] : null;
				  
				var info = new Template('<h1>#{title}</h1><h2>Posted on #{date}</h2><p>#{summary} <a href="#{more_link}">more &raquo;</a></p>');
				var html = info.evaluate(entry);
				
				$('timeline_entry').innerHTML = html;
				
				Effect.Appear('timeline_entry');
				
				if( current_entry < 1 )
					$('timeline_back').hide();
				else
					$('timeline_back').show();
				
				if( current_entry > 1 )
					$('timeline_next').hide();
				else
					$('timeline_next').show();				
				
			},					
			onFailure: function(){ alert('Something went wrong...') }
		});		
	}