$(function () {
	var widget, duration, minHeight;
	duration = 6000;
	minHeight = 40;
	widget = new Slippy({
		container: '#pizza-perfected-messageboard-delivery',
		item: '#pizza-perfected-messageboard-delivery li',
		duration: duration,
		minHeight: minHeight
	});
	widget = new Slippy({
		container: '#pizza-perfected-messageboard-frozen',
		item: '#pizza-perfected-messageboard-frozen li',
		duration: duration,
		minHeight: minHeight
	});
	widget = new Slippy({
		container: '#pizza-perfected-messageboard-homemade',
		item: '#pizza-perfected-messageboard-homemade li',
		duration: duration,
		minHeight: minHeight
	});
	
	$('.messageboard-widget-wide-what, .messageboard-widget-wide-talk').each(function () {
		$(this).css({
			paddingTop: ($(this.parentNode).height() - $(this).height()) / 2
		});
	});
});

$(function () {
	var tab,
		fragment,
		defaultTab = 'delivery';
		
	fragment = function (url) {
		var hash;
		hash = url.split('#');
		return hash[1] || defaultTab;
	};
	
	tab = function (key, click) {
		var pane;
		pane = $('#pizza-perfected-' + key);
		
		// Ensure that erroneous fragments don't mess things up.
		if (!pane.hasClass('pizza-perfected-pane')) {
			pane = $('#pizza-perfected-' + defaultTab);
		}
		
		// hide all the panes
		$('.pizza-perfected-pane').css({display: 'none'});
		
		// show the selected pane
		pane.css({display: 'block'});
		
		// track the event
		jsTrack.trackEvent('pizza-perfected-' + key);
		
		// track with eyeblaster if it exists and if this tab() call is the result of a click.
		if (click && eyeblaster_JSEvent) {
			eyeblaster_JSEvent(key);
		}
	};
	
	// make the imagemap areas change tabs
	$('.pizza-perfected-pane area').click(function () {
		tab(fragment(this.href), true);
	});
	
	// make the redundant bottom links change tabs,
	// and scroll to the top
	$('#pizza-perfected-redundancy a').click(function () {
		var href = this.href;
        $('html,body').animate({
        	scrollTop: $('#pizza-perfected-head').offset().top
        }, 300, function () {
        	tab(fragment(href), true);
        });
	});
	
	tab(fragment(window.location.href));
});
