$(document).ready(function(){
	$('#carousel #set').css('width', $('#carousel #set').children().length * 960);

	$('#carousel #controller .point').css('opacity', 0.5);

	$('#carousel #controller .point').hover(
		function(){
			if (!$(this).hasClass('active')){
				$(this).stop();
				$(this).animate({'opacity': '1'}, 200);
			}
		},
		function(){
			if (!$(this).hasClass('active')){
				$(this).stop();
				$(this).animate({'opacity': '0.50'}, 200);
			}
		}
	);

	$interval = setInterval('nextCarouselItem()', 21000);
	//nextCarouselItem();
	$('#carousel #controller .point').click(
		function(){
			if (!$(this).hasClass('active')){
				clearInterval($interval);
				$interval = setInterval('nextCarouselItem()', 21000);

				$('#carousel #controller .point').each(
					function(index){
						if ($(this).hasClass('active')){
							$(this).removeClass('active');
							$(this).animate({'opacity': '0.50'}, 200);
						}
					}
				);

				$(this).css('opacity', 1);
				$(this).addClass('active');
				$('#carousel #set').animate({'left': - $(this).attr('id').charAt(6) * 960}, 600);
			}
		}
	);

	$('#carousel #controller #point-0').click();
});


function nextCarouselItem(){
	$activeId = Number($('#carousel #controller .active').attr('id').charAt(6));
	$nextId = ($activeId + 1) % $('#carousel #controller').children().length;
	$('#carousel #controller #point-' + $nextId).click();
}
