ppl.coffeemakers = {

	init: function() {
		
		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.coffeemakers.mainCarouselCallback,
	        itemFirstInCallback: function(carousel, item, index) {
	        	jQuery('#main-carousel-control a').each(function(){
					$(this).toggleClass('current', (jQuery(this).text() == index));
				});
	        }
	    });
		
		$(window).load(function(){
			$(".product-row").each(function(){
				$children = $(this).children().find('.product-box .image-wrap');
				ppl.coffeemakers.setEqualHeight($children);
				$children = $(this).children().find('.product-box');
				ppl.coffeemakers.setEqualHeight($children);
			});
			ppl.coffeemakers.setEqualHeight($('.equal-height'));
		});
	
	},
	
	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();
	},
	
	setEqualHeight: function(columns) {
		var tallestcolumn = 0;
		columns.each(
			function() {
				currentHeight = $(this).height();
				if(currentHeight > tallestcolumn) {
					tallestcolumn  = currentHeight - 1;
				}
			}
		);
		columns.height(tallestcolumn);
	}

}

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