// JavaScript Document

var continue_loop = 0;
var in_progress = 0;


$(document).ready(function() {

	run_car();		
	
	$('#featured_list > li > a').click(function() {
		
		if (in_progress == 0) { do_car(this); }
		
		return false;
	
	});



						   });

function run_car() {
	
	var featured_items = new Array();
	featured_items = $('#featured_list > li > a'); 
	
	i = 0;
	
	cycle();
	
		function cycle() {
		
			if (continue_loop == 1) { return false; };
		
			//Fade out the element
			var activef = $('.active-s');
			var activei = featured_items[i];
			
			$(activef).fadeOut('slow', function() { 
			
				$(activef).removeClass('active-s');
				$(activei).removeClass('active');
			
			});
			// increment

			i++; if (i >= featured_items.length) { i = 0; }

			// Fade in new element
			
			var activei2 = featured_items[i];
					
			var target = $(activei2).attr('title');
			$('.' + target).fadeIn('slow');
			$('.' + target).addClass('active-s');	
			$(activei2).addClass('active');		
			$('.' + target).animate({opacity: 1.0}, 5000, function() { cycle(); });
		
		}
		
	}
	
function do_car(the_link) {
	
	continue_loop = 1;
	
	in_progress = 1;
	
	var target = $(the_link).attr('title');
	
	var activef = $('.active-s');
	
		$(activef).fadeOut('fast', function() {
											
			$(activef).removeClass('active-s');
			$('.active').removeClass('active');
			
			$('.' + target).fadeIn('fast');
			$('.' + target).addClass('active-s');
			$(the_link).addClass('active');
			
			in_progress = 0;
			
		});
		
		
	
	
	
}
	