var poochBagTotal;	
function ShoppCartAjaxHandler(cart) {
	jQuery('html, body').animate({
        scrollTop: 0
    }, function () {
		poochBagTotal.html(cart.Totals.quantity);    
    });
}

(function ($) {
	var links, topWrap, carouselTop, carouselBottom, months, cards, map, cat, monthScroll;
	
	$(document).ready(function () {
		poochBagTotal = $('.shopping .bag');
	
		links = $('.main-nav > li');
		links.bind('mouseenter mouseleave', function (e) {
			$(this)[(e.type === 'mouseenter' ? 'add' : 'remove') + 'Class']('focused');
		});
		
		if ($('body').hasClass('home')) {

			var current = 0, dots, slides, imgs;
			
			function doNext(indx) {
				return indx + 1 >= dots.length ? 0 : indx + 1;
			}
			
			function getNext() {
				current = doNext(current);
				return current;
			}
			
			function move() {
				dots.eq(current).addClass('on').siblings().removeClass('on');			
				imgs.hide().eq(current).fadeIn();	
			}
			
			function start() {
				slides = window.setInterval(function () {
					current = getNext();
					move();
				}, 7000);	
			}
			
			function showImage(i) {
				return function () {
					window.clearInterval(slides);
					current = i;
					move();
					start();
					return false;
				};
			}
			dots = $('.dots a');
			imgs = $('.top-items img');
			imgs.each(function (i) {
				$(this).click(showImage(doNext(i)));
			});
			dots.each(function (i) {
				$(this).click(showImage(i));
			}).eq(0).click();	
		
			map = new MonthMap();
			months = $('.months');
			cards = $('.days').find('ul');
			
			cards.each(function () {
				var items, elem = $(this);
				items = elem.find('li');
				
				elem.css('width', (items.length * 328) + 'px');
				if (items.length > 3) {
					elem.addClass('lots');	
				}
			});
			
			carouselBottom = new LazySusan(months, cards);
			carouselBottom.setCallback(function (index) {
				carouselBottom.setCurrent(map.getCurrent());
			});
			carouselBottom.init();
			
/*
			monthScroll = $('.days-scroll');
			monthScroll.jScrollPane();
			monthScroll.css('width', '700px');
*/
	
			$('.months ul li').eq((new Date()).getMonth()).click();
		}	
		
		$('.lazy-category').each(function () {
			var me, elem = $(this);		
			me = new LazySusan(elem.find('.lazy-nav'), elem.find('ul'));
			me.setCallback(function (indx) {
				elem.find('.currPage').text(indx + 1);
			});
			me.init();
		});
	});
}(jQuery));

