// JavaScript Document
/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        carousel.startAuto(0);		
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        carousel.startAuto(0);
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        carousel.startAuto(0);		
        return false;
    });
	
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function mycarousel_itemFirstInCallback(carousel, l, p, s) {
	jQuery('.jcarousel-control a:eq('+ (p-1) +')').addClass("currpage");
}

function mycarousel_itemLastOutCallback(carousel, l, p, s) {
	jQuery('.jcarousel-control a:eq('+ (p-1) +')').removeClass("currpage");
}

// Ride the carousel...
jQuery(document).ready(function() {
    jQuery("#mycarousel").jcarousel({
	    auto: 5,
		size:3,
		visible:1,
		vertical: true,
        wrap: 'last',
        scroll: 1,
        initCallback: mycarousel_initCallback,
		itemFirstInCallback: {onBeforeAnimation:mycarousel_itemFirstInCallback},
		itemLastOutCallback: {onBeforeAnimation:mycarousel_itemLastOutCallback},
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});
