/**

 * 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();

		return false;

	});



	jQuery('#mycarousel-prev').bind('click', function() {

		carousel.prev();

		return false;

	});

	

	// Disable autoscrolling if the user clicks the prev or next button.

	carousel.buttonNext.bind('click', function() {

		carousel.startAuto(0);

	});



	carousel.buttonPrev.bind('click', function() {

		carousel.startAuto(0);

	});



	// Pause autoscrolling if the user moves with the cursor over the clip.

	// carousel.clip.hover(function() {

	// 	carousel.stopAuto();

	// }, function() {

	// 	carousel.startAuto();

	// });

};



/**

 * Triggers before animation.

 */

function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {

	// No animation on first load of the carousel

	if (state == 'init')

		$("#carousel_nav1").addClass('picked');

	if (idx==1) {

		removePicked();

		$("#carousel_nav1").addClass('picked');

	}

	if (idx==2) {

		removePicked();

		$("#carousel_nav2").addClass('picked');

	}

	if (idx==3) {

		removePicked();

		$("#carousel_nav3").addClass('picked');

	}

	if (idx==4) {

		removePicked();

		$("#carousel_nav4").addClass('picked');

	}

	if (idx==5) {

		removePicked();

		$("#carousel_nav5").addClass('picked');

	}

	if (idx==6) {

		removePicked();

		$("#carousel_nav6").addClass('picked');

	}

	if (idx==7) {

		removePicked();

		$("#carousel_nav7").addClass('picked');

	}

	if (idx==8) {

		removePicked();

		$("#carousel_nav8").addClass('picked');

	}

	if (idx==9) {

		removePicked();

		$("#carousel_nav9").addClass('picked');

	}

	if (idx==10) {

		removePicked();

		$("#carousel_nav10").addClass('picked');

	}

	if (idx==11) {

		removePicked();

		$("#carousel_nav11").addClass('picked');

	}

};



function removePicked () {

	$("#carousel_nav1").removeClass('picked');

	$("#carousel_nav2").removeClass('picked');

	$("#carousel_nav3").removeClass('picked');

	$("#carousel_nav4").removeClass('picked');

	$("#carousel_nav5").removeClass('picked');

	$("#carousel_nav6").removeClass('picked');

	$("#carousel_nav7").removeClass('picked');

	$("#carousel_nav8").removeClass('picked');

	$("#carousel_nav9").removeClass('picked');

	$("#carousel_nav10").removeClass('picked');

	$("#carousel_nav11").removeClass('picked');

}



/**

 * Helper function for printing out debug messages.

 * Not needed for jCarousel.

 */

var row = 1;

function display(s) {

	// Log to Firebug (getfirebug.com) if available

	//if (window.console != undefined && typeof window.console.log == 'function')

	  //  console.log(s);



	if (row >= 1000)

		var r = row;

	else if (row >= 100)

		var r = '&nbsp;' + row;

	else if (row >= 10)

		var r = '&nbsp;&nbsp;' + row;

	else

		var r = '&nbsp;&nbsp;&nbsp;' + row;



	jQuery('#display').html(jQuery('#display').html() + r + ': ' + s + '<br />').get(0).scrollTop += 10000;



	row++;

};



// Ride the carousel...

jQuery(document).ready(function() {

	jQuery("#mycarousel").jcarousel({

		auto: 5,

		scroll: 1,

		initCallback: mycarousel_initCallback,

		

		itemVisibleInCallback: {

			onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation

		},

		

		// This tells jCarousel NOT to autobuild prev/next buttons

		buttonNextHTML: null,

		buttonPrevHTML: null

	});

});