tab_control = {
	init: function() {
		tab_control.setActiveTab();
		$('.signup-tabs-nav a.final').click(function(){ return false; });
		
		$('.signup-tabs-nav a:not(.final, .help)').click(function(){
			tab_control.selectTab( '.signup-tabs-nav', '.signup-tab-body' )(this);
			return false;
		});
		$('.tabs-nav a:not(.expander)').click(function(){
			tab_control.selectTab( '.tabs-nav', '.tab-body' )(this);
			return false;
		});
	},
	selectTab: function( nav_selector, body_selector ) {
		return function( el ) {
			var container_id = $(el).attr('href').substr(
				$(el).attr('href').lastIndexOf("#") + 1
			);
			$(body_selector).hide().filter('#'+container_id).show();
			$(nav_selector + ' li').removeClass('active');
			$(el).parent().addClass('active').siblings().removeClass('active');
		};
	},
	setActiveTab: function() {
		if( $(window.location.hash+'.tab-body').length == 1 ) {
			$(window.location.hash).show();
			$('.tabs-nav li a').filter(function(){
				return tab_control.endsWith( window.location.hash, $(this).attr('href') );
			}).parent().addClass('active');
		} else {
			$('.tabs-nav li:first').addClass('active');
			$('.tab-body:first').show();
		}
	},
	endsWith: function(needle, haystack){
		if(needle.length > haystack.length) return false;
		return haystack.indexOf(needle)==(haystack.length-needle.length);
	}
};
