$(document).ready(function(){
	
	var everything = $('p, h1, h2, h3,  a, span, li, aside');
	var colours = [
			'#3FA9F5',
			'#7AC943',
			'#FF931E',
			'#ED1C24',
			'#ED1E79',
			'#93278F',
			'#666666',
			'#754C24'		
		];

	animatePageIn();
				
	function animatePageIn(){				
						
		$("#body").removeClass('hidden')
		
		$('a').mouseenter(function(){
			$(this)
			.addClass('rollover')		
			.addClass('mouse-over')				
		});
		
		$('a').mouseleave(function(){
			$(this).removeClass('mouse-over')				
		})
				
		$('section').each(function(i){
			$(this).addClass('hidden')
			$(this)
				.delay(i*70)
				.fadeIn('slow')
			/*.animate({color: getRandomColor}, 500)
				.animate({color: '#000000'}, 300);	 */	
		});
		
		// wait for animation to finish
		$(this).delay((everything.length+1)*20).queue(function() {
		  addRollovers();
		});
	}
	
	function onRollover(_target){
		everything
			.stop()
			.animate({color: '#ffffff'}, 100)
		$('body')
			.stop()
			.animate({backgroundColor: colours[Math.floor(Math.random()*colours.length)]}, 100)
		$(_target)
			.stop()
			.css('color', '#000000')
			.animate({color: '#000'}, 200)	
	}
	
	function onRollout(_target){
						
		$(_target)
			
			.animate({color: '#fff'}, 200);		
		
		
		/*
window.setTimeout(function(){
		
			$('a').each(function(){
				if ($(this).hasClass('mouse-over')){
					return;
				}		
			})
					
			$('body')
				.stop()
				.animate({backgroundColor: '#ffffff'}, 100);
			everything
				.stop()
				.animate({color: '#000000'}, 100);	  
			
		},4000)		
*/
	}
	
	function addRollovers(){
		
		$('a').each(function(){
			if ($(this).hasClass('mouse-over')){
				onRollover(this);
			}		
		})
		
			
		$('a').each(function(){
			$(this).hover(
		  function () {
		  	onRollover(this)	
		  }, 
		  function () {
		    onRollout(this)
			});
		});
	}
}); 


