function mycarousel_initCallback(carousel) {
    $('#slideShowMenu .next').bind('click', function() {
        carousel.next();
        return false;
    });
    $('#slideShowMenu .prev').bind('click', function() {
        carousel.prev();
        return false;
    });
    $('#slideShowMenu a').bind('click', function() {
	 $(this).blur();
        carousel.scroll($.jcarousel.intval($(this).attr('id').slice(3)));
        carousel.startAuto(0);
        return false;
    });
};

function mycarousel_VisibleInCallbackBeforeAnimation(carousel,item,idx,state) {
	$("#slideShowMenu a").removeClass('selected');
	$("#slideShowMenu a#ss_"+idx+"").addClass('selected');
	$("#galleryInfo p").html($("#slideShowContainer ul li:nth-child("+idx+") span").html());
};

function mycarousel_VisibleInCallbackAfterAnimation(carousel,item,idx,state) { };

$(document).ready(function(){

	var hash = parseInt(parent.location.hash.slice(1));
	if (isNaN(hash)) { hash = 1; }
	
	var auto = 4;
	if ($("#galleryInfo").length>0) { var auto = 0; }
	
	$("#slideShowContainer").jcarousel({
   	   scroll: 1,
	   auto: auto,
	   start: hash,
	   wrap: 'both',
	   easing: 'easeInOutSine',
	   animation: 1000,
   	   initCallback: mycarousel_initCallback,
	   itemVisibleInCallback: {
		onBeforeAnimation: mycarousel_VisibleInCallbackBeforeAnimation,
		onAfterAnimation: mycarousel_VisibleInCallbackAfterAnimation
	   }
	});

	$("#projectThumbs a").each(function(){

		$(this).removeClass('noJS').hover(function(){
			$(this).children('span').fadeOut('slow');
		},function(){
			$(this).children('span').fadeIn('slow');
		});

	});
	
});
