var Universe = {
	
	init: function()
	{
		Universe.Parallax.init();
		Universe.Stars.init();
	}
};

Universe.Parallax = {
	
	init: function()
	{
		//this.trackMouse();
	},
	
	trackMouse: function()
	{
		$(document).mousemove(function(event)
		{
			var x = event.pageX;
			var y = event.pageY;
			
			var movementX = ((0 + ($(window).width() / 2)) - x);
			var movementY = ((0 + ($(window).height() / 2)) - y);
			
			$('#blueMarble h1, #getInvolved').css('right', movementX / 20);
			$('#blueMarble h1, #getInvolved').css('bottom', movementY / 20);
			
			$('#blueMarble').css('backgroundPosition', (50 + (movementX / 200)) + '% ' + (150 + (movementY / 10)) + 'px');
			$('body').css('backgroundPosition', (50 + (movementX / 500)) + '% ' + (0 - (movementY / 20)) + '%');
		});
	}
};

Universe.Stars = {
	
	init: function()
	{
		this.shine();
	},
	
	shine: function()
	{
		var self = this;
		
		setTimeout(function()
		{
			var star = $('.star.template').clone().removeClass('template')
			
			$(star).css({
				'opacity': 0,
				'top': Math.floor(Math.random() * $(window).height()),
				'left': Math.floor(Math.random() * $(window).width()),
				'webkitTranslate': 'rotate(' + Math.random() * 360 + 'deg)'
			});
			
			$('body').append(star);
			
			$(star).animate({
				opacity: 1
			}, 1000, function()
			{
				$(this).fadeOut(2000, function()
				{
					$(this).remove();
				});
			});
			
			self.shine()
		}, Math.floor(Math.random() * 5) * 1000);
	}
}

$(document).ready(Universe.init);


