function carousel_setup(carousel) {

    $('#carousel_indicator a').bind('click', function() {
        carousel.scroll($.jcarousel.intval($(this).text()));
        return false;
    });

	$('#carousel_forward').bind('click', function() {
		carousel.next();
		return false;
	});

	$('#carousel_back').bind('click', function() {
		carousel.prev();
		return false;
	});
};

function carousel_forward(carousel, control_element, flag) {
	if (!flag) {
		$('#carousel_forward').fadeOut();
	} else {
		$('#carousel_forward').fadeIn();
	}
}

function carousel_back(carousel, control_element, flag) {
	if (!flag) {
		$('#carousel_back').fadeOut();
	} else {
		$('#carousel_back').fadeIn();
	}
}

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 */
 
function carousel_callback(carousel, item, idx, state) {
	
	//console.log('item:' + item.getAttribute('id'));
	
	id = item.getAttribute('id');
	
	// strip off the last character
	var active_indicator = 'indicator-' + id.substr(-1, 1);
	
	//console.log(active_indicator);
	
	$('#carousel_indicator a').each(
		function() {
			if ($(this).attr('id') == active_indicator) {
				$(this).addClass('on');
			} else {
				$(this).removeClass('on');
			}
		}
	);
			
    
};


$(document).ready(

	function() {
	
		if ($('#group_photos').is(":visible")) {
    	
			$('#group_photos').jcarousel({
				scroll: 1,
				wrap: 'circular',
				initCallback: carousel_setup,
				itemFirstInCallback:  carousel_callback,
				buttonNextHTML: null,
        		buttonPrevHTML: null
			});
			
		}
		
		$("a.fancybox").fancybox({
			'hideOnContentClick' : true,
			'autoScale' : false,
			'width' : 800,
			'titleShow' : false
		});
	
	}
	
);
