function mycarousel_initCallback(carousel){
	// 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();
	});
};

$(document).ready(function() {
	Cufon('#nav li a', {
		hover: {
			color: '#FFF'
		}
	});

	Cufon.replace('#nav li a');

	$('#slider1').cycle({
		fx: 'fade',
		cleartype: true,
		cleartypeNoBg: true
	});

	$('#wedding-gallery').jcarousel({
		auto: 0,
		scroll: 1,
		wrap: 'last',
		initCallback: mycarousel_initCallback
	});
	
	$('a.wedding-gallery-link').fancybox({
		cyclic: true,
		showCloseButton: false,
		centerOnScroll: true
	});
	
	$('#page-gallery-cycle .page-gallery-link').fancybox({
		auto: 2,
		cyclic: false,
		showCloseButton: false//,
//		onStart: function(e, index){
//			console.log(e);
//			console.log(index);
//			var carousel = $('#page-gallery').data('jcarousel');
//			if(carousel){
//				carousel.scroll(index, true);
//			}
//			$('#page-gallery-cycle').cycle(index);
//		}
	});
	
	function cycleOnBefore(curr, next, opts, fwd){
		var index = $(this).index();
		//change selector to relevant jCarousel element
		var carousel = $('#page-gallery').data('jcarousel');
		if(carousel){
			carousel.scroll(index, true);
		}
	}
	
	
	$('#page-gallery-cycle').cycle({
		fx: 'fade',
		pause: 1,
		timeout: 2000,
		pager: '#page-gallery',
		pagerAnchorBuilder: function(idx, slide){
			return '#page-gallery li:eq(' + idx + ') a';
		},
//		next: $('#page-gallery-cycle').click(),
//		cleartype: true,
//		cleartypeNoBg: true,
		before: cycleOnBefore//,
//		after: cycleOnAfter
	});
	
	$('#page-gallery').jcarousel({
		auto: 0,
		scroll: 1,
		wrap: 'last'
	})
	
	$('.bookOnline').fancybox({
		type: 'iframe',
		showCloseButton: false,
		autoDimensions: false,
		width: 600,
		height:500,
		centerOnScroll: true,
		padding: 0
	});
	
	$('a#map').fancybox({
		type: 'iframe',
		showCloseButton: false,
		autoDimensions: false,
		width: 600,
		height: 500,
		centerOnScroll: true,
		padding: 10
	});
	
	$('.blog_archive_list .year.past .year_list, .blog_archive_list .year.past .month_list').hide();
	$('.blog_archive_list .year_list .month').not(':first-child').children('.month_list').hide();
	$('.year_header, .month_header').addClass('expandable');
	$('.blog_archive_list .year .year_header, .blog_archive_list .month .month_header').click(function(){
		$(this).next().slideToggle();
	});
	
	$('#page-gallery-cycle .item span.caption').hide();
	$('#page-gallery-cycle .item a').mouseenter(function(e){
//		e.stopPropagation();
		$(this).children('span.caption').stop(true, true);
		$(this).children('span.caption').css('opacity', 1);
		$(this).children('span.caption').fadeIn(500);
	});
	$('#page-gallery-cycle .item a').mouseleave(function(e){
//		e.stopPropagation();
		$(this).children('span.caption').stop(true, true);
		$(this).children('span.caption').css('opacity', 1);
		$(this).children('span.caption').fadeOut(500).css('opacity', 0);
	});
	
	$('#tabbed_content').tabs().removeClass('ui-corner-all').addClass('ui-tabs-vertical ul-helper-clearfix');
	$("#tabbed_content .ui-tabs-panel").removeClass('ui-corner-bottom');
	$("#tabbed_content li").removeClass('ui-corner-top');
	
	$('img.alt_helper').error(function(){
		$(this).replaceWith($(this).attr('alt'));
	});
});
