function resizeUnderTab() {
	var t = $('#header table.header-row-2 div.tw-l');
	if (!t.length) return false;
	var twidth = 0
	var go = -1;
	var lastActive = false;
	$('#header table.header-row-2 td.tabs div.tab').each(function() {
		$this = $(this);
		if (go <= this.offsetLeft) {
			lastActive = ($this.hasClass('active'));
			twidth += $this.width() + parseInt($this.css('marginRight').replace('px', '')) + parseInt($this.css('marginLeft').replace('px', ''));
			go = this.offsetLeft;
		}
	});
	if (lastActive) twidth -= 5;
	t.css({'width': twidth});
	return true;
}
function showHiddenTab( _parent ) {
	$('#hidden-tabs').remove();
	var html = "";
	var go = -1;
	var collect = false;
	$('#header table.header-row-2 td.tabs div.tab').each(function() {
		$this = $(this);
		
		if ($this.hasClass('tab-sep')) return;
		
		if (go < this.offsetLeft) go = this.offsetLeft; 
		else collect = true;
		
		if (collect) html += '<li>'+$this.html()+'</li>';
		
	});
	$('#header').after('<div id="hidden-tabs"></div>');
	$('#hidden-tabs')
		.css({'visibility':'hidden'})
		.append('<div class="line"></div><ul>'+html+'</ul>')
		.css({'left': $(_parent).offset().left - 1 })
		.css({'display':'none', 'visibility':''})
		.fadeIn('fast');
	if ($(_parent).parent().hasClass('tab-sep-active')) {
		$('#hidden-tabs').addClass('tabs-active');
	}
	return false;
}
function hideHiddenTabs() {
	$('#hidden-tabs').fadeOut('fast', function() { $(this).remove() });
	//$(document).unbind('click', hideHiddenTabs);
}

$(function() {
	
	var t = $('#header table.header-row-2 div.tw-l');
	t.hide();
	if (t.length) {
		//setTimeout(resizeUnderTab, 0);
	}
	$('#header table.header-row-2 div.tab-sep a').mousedown( function( e ) {
		showHiddenTab( this ); 
		return false;
	}).click( function( e ) {
		e.stopPropagation();
	});
	//$( window ).bind( 'resize', function() { setTimeout(resizeUnderTab, 0); } );
	$( document ).bind('click', hideHiddenTabs);
	$( window ).bind( 'resize', hideHiddenTabs );

	
});