	$(document).ready(function()
	{	 
	    // Check for hash value in URL. If there is no hash then load the script for this page itself.
		var hash = window.location.hash.substr(1);
		
		if (hash.length > 0)
		{
			var href = $('#nav a').each(function()
			{
				var href = $(this).attr('href');
				
				if(hash==href.substr(0,href.length-4))
				{
					loadPage( hash );
				} 
			});
		}
		else
		{
			var sPath = window.location.pathname;
			var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);			
			sPage = sPage.substring(0, sPage.length - 4);
			
			if (sPage.length > 0)
				$.getScript(sPage + '.js');
			else
				$.getScript('index.js');
			
			activateLightbox();
		}
    
		$('#nav a.jsLink').click(function()
		{					
			var pageName = $(this).attr('href').substr(0,$(this).attr('href').length-4);
			loadPage( pageName );			
			return false;		
		});
		
		setInternalLinks();
	});
	
	function loadPage( pageName )
	{
		$('#contentHolder').load(pageName + '.php #content', '', function() 
		{
			var scriptFile = pageName + '.js';
			
			$.getScript(scriptFile);
			
			activateLightbox();			
			setInternalLinks();
		});
		

								
		window.location.hash = pageName;
	}
	
	function setInternalLinks()
	{
		$('.internallink').click(function()
		{					
			var pageName = $(this).attr('href').substr(0,$(this).attr('href').length-4);
			loadPage( pageName );			
			return false;		
		});
	}

	function activateLightbox()
	{
		// Activate any lightbox images
		$('area.lightbox').lightBox();
		$('a.lightbox').lightBox();
	}	
