/*global $ */
$(function () {
	var container, lists, height, goTo, i, pager, link, pagerLinks;
	
	lists = $('#store-sidebar-list ul');

	if (lists.length > 1) {

		goTo = function (index) {
			lists.css({
				display: 'none'
			});
			$(lists[index]).css({
				display: 'block'
			});
			pagerLinks.removeClass('store-sidebar-list-pager-current');
			$(pagerLinks[index]).addClass('store-sidebar-list-pager-current');
		};
		
		container = $('#store-sidebar-list');
		pager = $('#store-sidebar-list-pager').append('Page: ');
		height = 0;
		
		i = 0;
		
		lists.each(function () {
			var self = $(this);
			
			// update the height needed for container
			height = Math.max(height, self.height());
			
			// create the link to this list
			link = $('<span>' + (i + 1) + '</span>').css({
				
			});
			(function (i) {
				link.click(function () {
					goTo(i);
				});
			}(i));

			pager.append(link);
			
			i += 1;

		});
		
		pagerLinks = $('#store-sidebar-list-pager span');
		
		lists.css({
			position: 'absolute',
			top: 0,
			left: 0,
			display: 'none'
		});

		container.css({
			position: 'relative',
			top: 0,
			left: 0,
			height: height
		});
		
		goTo(0);
	
	}
	
});

