$(document).ready(function() 
{
	var animation = false;
	var current = 'a-1';
	
	$('.'+current).addClass('active');

	$('#'+current).show(); $('#b-menu').hide(); $('#c-menu').hide();
	
	$('#'+current).css({'visibility' : 'visible'}); // ie fix
	
	$('#'+current).show(); $('#'+'a-2').hide(); $('#'+'a-3').hide(); $('#'+'a-4').hide();
	$('#'+'b-1').hide();   $('#'+'b-2').hide(); $('#'+'b-3').hide(); $('#'+'b-4').hide();
	$('#'+'c-1').hide();   $('#'+'c-2').hide(); $('#'+'c-3').hide(); $('#'+'c-4').hide();
	
	$('#feature-a').click(function() { showInitialSection('a-1'); });
	$('#feature-b').click(function() { showInitialSection('b-1'); });
	$('#feature-c').click(function() { showInitialSection('c-1'); });
	
	$('.a-1').click(function() { showTargetSection('a-1'); });
	$('.a-2').click(function() { showTargetSection('a-2'); });
	$('.a-3').click(function() { showTargetSection('a-3'); });
	$('.a-4').click(function() { showTargetSection('a-4'); });
	
	$('.b-1').click(function() { showTargetSection('b-1'); });
	$('.b-2').click(function() { showTargetSection('b-2'); });
	$('.b-3').click(function() { showTargetSection('b-3'); });
	$('.b-4').click(function() { showTargetSection('b-4'); });
	
	$('.c-1').click(function() { showTargetSection('c-1'); });
	$('.c-2').click(function() { showTargetSection('c-2'); });
	$('.c-3').click(function() { showTargetSection('c-3'); });
	$('.c-4').click(function() { showTargetSection('c-4'); });
	
	function showInitialSection(target)
	{
		if (current != target && !animation)
		{
			// set animation flag
			animation = true;
			
			// move feature arrow
			var newArrowPosition = 0;
			var newArrowPositionOffset = 0;
			
			var currentSection = current.substr(0,1);
			var currentTarget = target.substr(0,1);
			
			// mei shi jian, jiu zhe yang ba...
			if (currentSection == 'a' && currentTarget == 'b') 
			{
				newArrowPositionOffset = 1;
			}
			else if (currentSection == 'a' && currentTarget == 'c')
			{
				newArrowPositionOffset = 2;
			}
			else if (currentSection == 'b' && currentTarget == 'a')
			{
				newArrowPositionOffset = -1;
			}
			else if (currentSection == 'b' && currentTarget == 'c')
			{
				newArrowPositionOffset = 1;
			}
			else if (currentSection == 'c' && currentTarget == 'a')
			{
				newArrowPositionOffset = -2;
			}
			else if (currentSection == 'c' && currentTarget == 'b')
			{
				newArrowPositionOffset = -1;
			}
			
			newArrowPosition = 94 * newArrowPositionOffset;
			
			$('#feature-arrow').animate({"top": "+="+newArrowPosition+"px"}, "slow");
			
			// fade out menu
			$('#'+current.substr(0,1)+'-menu').fadeOut();
			
			// fade out currently featured content
			$('#'+current).fadeOut(function()
			{
				// update menu
				$('.'+current).removeClass('active');
				$('.'+target).addClass('active');
				
				// fade in target menu and content
				$('#'+target).css({'visibility' : 'visible'}); // ie fix
				$('#'+target.substr(0,1)+'-menu').fadeIn();
				$('#'+target).fadeIn();
				current = target;
				
				// unset animation flag
				animation = false;
			});
		}
	}
	
	function showTargetSection(target)
	{
		if (current != target && !animation)
		{
			// set animation flag
			animation = true;
			
			// update menu
			$('.'+current).removeClass('active');
			$('.'+target).addClass('active');
			
			// fade out currently featured content
			$('#'+current).fadeOut(function()
			{
				$('#'+target).css({'visibility' : 'visible'}); // ie fix
				$('#'+target).fadeIn();
				current = target;
				
				// unset animation flag
				animation = false;
			});
		}
	}
});


