ppl.home = {

	init: function() {
		
		$("#top-coffees").tabs();
		
		startIndex = Math.floor(Math.random() * $("#main-carousel > li").size()) + 1;
		jQuery('#main-carousel').jcarousel({
			start: startIndex,
			scroll: 1,
	        auto: 12,
	        wrap: 'last',
	        buttonNextHTML: null,
	        buttonPrevHTML: null,
	        initCallback: ppl.home.mainCarouselCallback,
	        itemFirstInCallback: function(carousel, item, index) {
	        	jQuery('#main-carousel-control a').each(function(){
					$(this).toggleClass('current', (jQuery(this).text() == index));
				});
	        }
	    });
		
		jQuery('#sub-carousel').jcarousel({
			scroll: 4,
	        auto: 10,
	        // wrap: 'last',
	        initCallback: ppl.home.subCarouselCallback
	    });
		
		$(window).load(function(){
			ppl.main.setEqualHeight($('.staff-pick-inner'));
			ppl.main.setEqualHeight($('.information-box'));
		});
	
	},
	
	mainCarouselCallback: function(carousel) {
		jQuery('#main-carousel-control a').bind('click', function() {
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
			carousel.startAuto(0);
			return false;
		});
		jQuery('#main-carousel-control').show();
	},
	
	subCarouselCallback: function(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();
		});
	
	}

}

jQuery(document).ready(function() {
    ppl.home.init();
});
