function mycarousel_initCallback(carousel) {
    var $jcarousel_total_count = jQuery('#splash ul li').size(),
    $jcarousel_content_control = '<a class="1" href="#">1</a>',
    $jcarousel_current = 1;
    while ($jcarousel_current <= $jcarousel_total_count) {
	var $jcarousel_current_content = jQuery('#splash_details_wrapper div.jcarousel-control').html();
	jQuery('#splash_details_wrapper div.jcarousel-control').html($jcarousel_current_content+'<a class="'+$jcarousel_current+'" href="#">'+$jcarousel_current+'</a>');
	$jcarousel_current ++;
    }
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
};

function beforeanimation() {
	jQuery('.jcarousel-control a').removeClass('current');
}
function afteranimation(carousel, state){
	var $jcarousel_total_count = jQuery('#splash_details_wrapper div.jcarousel-control a').size();
	if (carousel.first > $jcarousel_total_count) {
	    var $jcarousel_cur_num = carousel.first - $jcarousel_total_count;
	    jQuery('.jcarousel-control').find('a.'+$jcarousel_cur_num).addClass('current');
	} else {
	    jQuery('.jcarousel-control').find('a.'+carousel.first).addClass('current');
	}
	var $splash_detail_title = jQuery('#splash ul').find('li[jcarouselindex|="'+carousel.first+'"] div h2').html(),
	    $splash_detail_teaser = jQuery('#splash ul').find('li[jcarouselindex|="'+carousel.first+'"] div p').html(); 
	jQuery('#splash_details_wrapper div').find('h2').html($splash_detail_title);
	jQuery('#splash_details_wrapper div').find('p').html($splash_detail_teaser);
};

// Ride the carousel...
jQuery(document).ready(function() {
    jQuery("#splash").jcarousel({
        auto: 5,
        wrap: 'circular',
		scroll: 1,
		rtl: true,
        initCallback: mycarousel_initCallback,
		itemVisibleInCallback: {
								onBeforeAnimation: beforeanimation,
								onAfterAnimation: afteranimation
		},
		buttonNextHTML: null,
		buttonPrevHTML: null,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});
