/*global $ */

// specifications tabs
$('#product-halo-spectabs').css({
	display: 'none'
});
$(function () {
	var tabs, sections, init;
	
	$('#product-halo-spectabs').css({
		display: 'block'
	});
	
	tabs = $('#product-halo-spectabs-tabs');
	sections = [];
	init = null;
	
	$('.product-halo-spectabs-section h2').each(function () {
		var section, tab, i, pick;
		
		tab = this;
		section = tab.parentNode;
		sections.push({section: section, tab: tab});
		section.removeChild(tab);
		$(section).css({
			display: 'none'
		});
		$(tab).css({
			cursor: 'pointer'
		});
		
		tabs.append(tab);

		pick = function () {
			for (i = 0; i < sections.length; i += 1) {
				$(sections[i].section).css({
					display: 'none'
				});
				$(sections[i].tab).removeClass('product-halo-spectabs-current');
			}
			$(section).css({
				display: 'block'
			});
			$(tab).addClass('product-halo-spectabs-current');
		};
		
		$(tab).click(function () {
			pick();
		});

		if (!init) {
			init = pick;
		}
	});
	
	init();

});


// squish
$(function () {
	void new Squish({
		item: '#product-halo-faq-what li',
		heading: '#product-halo-faq-what h3',
		content: '#product-halo-faq-what div.product-halo-faq-content',
		openClass: 'product-halo-faq-current'
	});
	void new Squish({
		item: '#product-halo-faq-proven li',
		heading: '#product-halo-faq-proven h3',
		content: '#product-halo-faq-proven div.product-halo-faq-content',
		openClass: 'product-halo-faq-current'
	});
	void new Squish({
		item: '#product-halo-faq-power li',
		heading: '#product-halo-faq-power h3',
		content: '#product-halo-faq-power div.product-halo-faq-content',
		openClass: 'product-halo-faq-current'
	});
});

// halo tabs
$(function () {

	var tabs,
		select;

	select = function (id) {
		// turn off all panes, tabs, and sidebars
		panes.css({display: 'none'});
		tabs.removeClass('product-halo-nav-current');
		sidebars.css({display: 'none'});
		
		// turn on specific pane, tab, and sidebar
		$('#' + id).css({display: 'block'});
		$('#product-halo-nav-' + id).addClass('product-halo-nav-current');
		$('#product-halo-sidebar-' + id).css({display: 'block'});
	};
	
	tabs = $('#product-halo-nav li');
	panes = $('.product-halo-body-content-pane');
	sidebars = $('.product-halo-sidebar-inner');
	
	tabs.each(function () {
		var li,
			a;
		
		// the LI element representing the tab
		li = $(this);
		
		// the clickable link inside it
		a = $('#' + this.id + ' a');
		
		// switch to the proper tab on click.
		a.click(function () {
			select(a[0].href.split('#')[1]);
			return false;
		});
		
	});
	
	select('power');

});