var current_banner = 0, banner_animation = null, total_banners;
var $ = jQuery;


function show_banner(index)
{
	$('#car-pictures > li:visible').fadeOut();
	$('#car-content > li:visible').fadeOut();
	
	$('#car-pictures > li:eq(' + index + ')').fadeIn();
	$('#car-content > li:eq(' + index + ')').fadeIn();
	
	$('#slider-pagination a').removeClass('active');
	$('#slider-pagination a:eq(' + index + ')').addClass('active');
	
	current_banner = index;
}

function rotate_banners()
{
	var new_banner_index;
	
	if ((current_banner + 1) < total_banners) {
		new_banner_index = current_banner + 1;
	} else {
		new_banner_index = 0;
	}
	
	show_banner(new_banner_index);
}

function stop_banner_animation()
{
	clearTimeout(banner_animation);
	banner_animation = null;
}

function start_banner_animation()
{
	banner_animation = setInterval('rotate_banners();', 7000);
}

(function($) {
	
	$(function()  {
		total_banners = $('#car-pictures > li').length;
	
		$('#slider').hover(function() {
			stop_banner_animation();
		}, function() {
			start_banner_animation();
		});
		
		$('#slider-pagination a').click(function() {
			var index = $(this).attr('index');
			
			$('#square-dots a').removeClass('active');
			$(this).addClass('active');
			
			show_banner(index);
			
			return false;
		});
		
		start_banner_animation();
	});
	
})(jQuery);
