
	$(document).ready(function(){
		fireJS();
		// check for the hash value in the url
		var hash = window.location.hash.substr(1);
		var href = $('#nav li a').each(function(){
			var href = $(this).attr('href');
			if(hash == href.substr(0,href.length-4)){
				var toLoad = hash + '.php #content'
				$('#content').load(toLoad,'',function(){
					fireJS();
				});
			}
		});
		
		$('#nav li a').click(function(){
			var toLoad = $(this).attr('href') + ' #content';
			$('#nav li a').removeClass('active');
			$(this).addClass('active');
			// if it's the blog link just act on it
			if($(this).hasClass('blog')){
				return true;
			}
			// if this is the about link - add the submenu and the submenu class to the #menu
			if($(this).hasClass('about') || $(this).parents('ul').siblings('a').hasClass('about')){
				var addUL = true;
				if($(this).parents('ul').siblings('a').hasClass('about')){
					addUL = false;
				}
				if(addUL){
					// load the submenu
					var ulLoad = $(this).attr('href') + ' #about-sub-menu li';
					var ul = $(document.createElement('ul'));
					ul.attr('id','about-sub-menu');
					$(this).after(ul);
					
					ul.load(ulLoad,'',function(){
					});
					
					$('#menu').animate({height: '100px'}, 200);
					$('#menu').addClass('submenu');
				}
			}
			else {
				$('#menu').animate({height: '55px'}, 200);
				$('#menu').removeClass('submenu');
				$('#about-sub-menu').remove();
			}
			$('#content').fadeOut('fast', loadContent);
			$('#load').remove();
			$('#wrapper').append('<div id="load">loading...</div>');
			$('#load').fadeIn('normal');
			
			window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);
			
			function loadContent(){
				$('#content').load(toLoad,'', showNewContent());
			}
			
			function showNewContent(){
				$('#content').fadeIn('normal', function(){
					fireJS();
					$('#load').fadeOut('normal');
				});
			}
			
			function hideLoader(){
				$('#load').fadeOut('normal');
			}
			
			return false;
		});
		
		function fireJS(){
			scroller($('#portfolio-desc'),75);
			scroller($('#faq-main ul'),50);
			scroller($('#about-description'),50);
			scroller($('#press-lists'), 100);
			scroller($('#lists'), 100);
			
			
			$('#about-links li a').click(function(){
				$('#about-links li a').removeClass('active');
				$(this).addClass('active');
				var toLoad = $(this).attr('href') + ' #about-description';
				$('#about-description').fadeOut('fast', loadContent);
				
				function loadContent(){
					$('#about-description').load(toLoad,'',showNewContent);
				}
				
				function showNewContent(){
					$('#about-description p').unwrap();
					scroller($('#about-description'),50);
					$('#about-description').fadeIn('normal');
				}
				return false;
			});
		}
	});
