/**
 * We use the itemFirstInHandler callback
 * to assign functionality to the controls
 */
function itemFirstInHandler(carousel, li, idx, state) {
    if (state != 'init')
        return;

    var cr = carousel;

    jQuery(".jcarousel-control").bind("click", function() {
        //cr.scroll(parseInt(jQuery(this).attr('title')));
		if(jQuery(this).attr('title') == 'next')			
			cr.next();
		else
			cr.prev();
			
        return false;
    });
	
	jQuery("ul li a").bind("click", function() {
        t = jQuery(this).attr('rel');
        f = jQuery(this).attr('rev');
		if(!f)
			f = t;
			
		jQuery('#carouselcontentwrap div').hide().html(jQuery('#'+t).html()).fadeIn();
		//jQuery('#carouselcontentimage').hide().attr('src',jQuery(this).attr('href')).fadeIn();
		jQuery('#carouselcontentimage').attr('src',jQuery(this).attr('href'));
		jQuery('#carouselcontentimagelink').attr('border',0);
		jQuery('#carouselcontentimagelink').attr('href',f);
		jQuery('#carouselcontentimagelink').attr('target','_blank');
		return false;
    });
	jQuery("ul li a:eq(0)").click();
}

// Ride the carousel...
jQuery(document).ready(function() {
    jQuery("#mycarousel").jcarousel({
        itemScroll: 1,
        itemFirstInHandler: itemFirstInHandler,
		wrap: true,
		wrapPrev: true,
		noButtons: true,
		itemVisible: 4
    });
});
