$(document).ready(function() {
	$('#frontpagecarouselpreloader').remove();
	$('#tha_carousel').show();

	set_carousel_nav();

});


function fpmaincarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
};

jQuery(document).ready(function() {
    jQuery("#fpmaincarousel").jcarousel({
        scroll: 1,
        initCallback: fpmaincarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});


function set_carousel_nav()
{
	// If this isn't the front page, ignore everything
	if($('body.home').length < 1) return;
	$col_width = 960 / $('.jcarousel-control a').length;
	// Create the indicator
	$i = document.createElement('div');
	$i.id = 'carousel_nav_indicator';
	$i.style.width = $col_width + 'px';

	$('#container').prepend($i);

	$('.jcarousel-control a:first-child').addClass('active');

	$('.jcarousel-control a').click(function(e)
	{
		var my_col = $(this).attr('href').replace('#', '') - 1;

		$('.jcarousel-control a').removeClass('active');
		$(this).addClass('active');

		$($i).animate({
			marginLeft : 0 + my_col * $col_width
		});
	});
}


