function carousel_init(id,count,auto_speed,scroll_count)
{
	var count = parseInt(count);
	
	if(count == 1)
	{
		auto_speed = 0;
		scroll_count = 0;
	}
		
	$(id + ' .carousel_content').jCarouselLite({
		btnNext: id + " .carousel_right",
		btnPrev: id + " .carousel_left",
		btnGo: carousel_buttons(id,count),
		visible: count,
		speed: 500,
		scroll: scroll_count,
		auto: auto_speed,
		mouseWheel: true,
		afterEnd: afterAnimation
	});

	$(id + ' .carousel_nav a').bind('click', function() {
		highlight(this);
    });
}

function carousel_buttons(id,count)
{
	var buttons = new Array();
	
	for(x = 0; x < count; x++)
		buttons[x] = id + " .carousel_nav a:eq(" + x + ")";
	
	return buttons;
}

function highlight(object)
{
	var carousel_id = $(object).parents('.carousel').attr('id');
	$('#' + carousel_id + ' .carousel_nav a').removeClass('active');
	$(object).addClass('active');
}

function afterAnimation(active)
{
	var carousel_id =  active.parents('.carousel').attr('id');
	var imgPos = parseInt(active.attr('title'));
	highlight("#"+ carousel_id + " .carousel_nav a:eq(" + imgPos + ")");
}
