$(document).ready(function() 
{
	function closeAllShelfDetails(functionChain)
	{
		if( functionChain == null )
		{
			functionChain = function(){};
		} 

		if ($('#battleships_detail').is(":hidden") == false)
		{
			$('#battleships_detail').slideUp("slow", functionChain);
		}
		else if ($('#ootp_detail').is(":hidden") == false)
		{
			$('#ootp_detail').slideUp("slow", functionChain);
		}
		else if ($('#hbp_detail').is(":hidden") == false)
		{
			$('#hbp_detail').slideUp("slow", functionChain);
		}
		else if ($('#nfss_detail').is(":hidden") == false)
		{
			$('#nfss_detail').slideUp("slow", functionChain);
		}
		else if ($('#unannounced_detail').is(":hidden") == false)
		{
			$('#unannounced_detail').slideUp("slow", functionChain);
		}
		else if ($('#create_detail').is(":hidden") == false)
		{
			$('#create_detail').slideUp("slow", functionChain);
		}
		else
		{
			functionChain();
		}
	}
	
	function closeAllSoftgraphy()
	{
		closeAllShelfDetails();
		
		if ($('#shelf_project_close_bar').is(":hidden") == false)
		{
			$('#shelf_project_close_bar').slideUp("slow");
		}
		
		if ($('#shelf_display').is(":hidden") == false)
		{
			$('#shelf_display').slideUp("slow");
		}
	}
	
	$('#about_bar').click(function() 
	{
		closeAllSoftgraphy();
		
		if ($('#about_text').is(":hidden"))
		{
			$('#about_text').slideDown("slow");
			$('html, body').animate({ scrollTop: $('#about_bar').offset().top }, 'slow');
		} 
		else 
		{
			$('#about_text').slideUp("slow");
		}
	});
	
	$('#shelf_bar').click(function() 
	{
		closeAllShelfDetails();
		
		if ($('#about_text').is(":hidden") == false)
		{
			$('#about_text').slideUp("slow");
		}
		
		if ($('#shelf_project_close_bar').is(":hidden") == false)
		{
			$('#shelf_project_close_bar').slideUp("slow");
			$('html, body').animate({ scrollTop: $('#shelf_bar').offset().top }, 'slow');
		}
		
		if ($('#shelf_display').is(":hidden"))
		{
			$('#shelf_display').slideDown("slow");
		} 
		else 
		{
			$('#shelf_display').slideUp("slow");
		}
	});
	
	$('#shelf_project_close_bar').click(function() 
	{
		if ($('#shelf_project_close_bar').is(":hidden") == false)
		{
			closeAllShelfDetails(function(){});
			$('#shelf_project_close_bar').slideUp("slow");
			$('html, body').animate({ scrollTop: $('#shelf_bar').offset().top }, 'slow');
			
		}
	});
	
	// All the individual projects
	$('#ootp_cover').click(function() 
	{
		if ($('#ootp_detail').is(":hidden"))
		{
			closeAllShelfDetails(function(){
				$('#ootp_detail').slideDown("slow");
				$('html, body').animate({ scrollTop: $('#ootp_detail').offset().top }, 'slow');
				});
			
			if ($('#shelf_project_close_bar').is(":hidden"))
			{
				$('#shelf_project_close_bar').slideDown("slow");
			}
		}
	});
	
	$('#hbp_cover').click(function() 
	{
		if ($('#hbp_detail').is(":hidden"))
		{
			closeAllShelfDetails(function(){
				$('#hbp_detail').slideDown("slow");
				$('html, body').animate({ scrollTop: $('#hbp_detail').offset().top }, 'slow');
				});
			
			if ($('#shelf_project_close_bar').is(":hidden"))
			{
				$('#shelf_project_close_bar').slideDown("slow");
			}
		}
	});
	
	$('#nfss_cover').click(function() 
	{
		if ($('#nfss_detail').is(":hidden"))
		{
			closeAllShelfDetails(function(){
				$('#nfss_detail').slideDown("slow");
				$('html, body').animate({ scrollTop: $('#nfss_detail').offset().top }, 'slow');
				});
			
			if ($('#shelf_project_close_bar').is(":hidden"))
			{
				$('#shelf_project_close_bar').slideDown("slow");
			}
		}
	});
	
	$('#unannounced_cover').click(function() 
	{
		if ($('#unannounced_detail').is(":hidden"))
		{
			closeAllShelfDetails(function(){
				$('#unannounced_detail').slideDown("slow");
				$('html, body').animate({ scrollTop: $('#unannounced_detail').offset().top }, 'slow');
				});
			
			if ($('#shelf_project_close_bar').is(":hidden"))
			{
				$('#shelf_project_close_bar').slideDown("slow");
			}
		}
	});
	
	$('#create_cover').click(function() 
	{
		if ($('#create_detail').is(":hidden"))
		{
			closeAllShelfDetails(function(){
				$('#create_detail').slideDown("slow");
				$('html, body').animate({ scrollTop: $('#create_detail').offset().top }, 'slow');
				});
			
			if ($('#shelf_project_close_bar').is(":hidden"))
			{
				$('#shelf_project_close_bar').slideDown("slow");
			}
		}
	});
	
	$('#battleships_cover').click(function() 
	{
		if ($('#battleships_detail').is(":hidden"))
		{
			closeAllShelfDetails(function(){
				$('#battleships_detail').slideDown("slow");
				$('html, body').animate({ scrollTop: $('#battleships_detail').offset().top }, 'slow');
				});
			
			if ($('#shelf_project_close_bar').is(":hidden"))
			{
				$('#shelf_project_close_bar').slideDown("slow");
			}
		}
	});
});

