if (typeof (Website) == 'undefined')
{
	var Website = new Object ();
}

Website.easteregg = 
{
	'stage' : null,
	'square' : null,
	'counter' : 0,
	'startDate' : null,
	'afterFinish' : function () { },

	/*
		Clear the screen and start the easter egg
	*/
	'start' : function (settings)
	{
		if (typeof (settings) != 'undefined')
		{
			if (typeof (settings.afterFinish) != 'undefined')
			{
				Website.easteregg.afterFinish = settings.afterFinish;
			}
		}
		
		document.body.style.height = '100%';
	
		// Make us a stage
		var stage = document.createElement ('div');
		
		stage.style.background = 'white';
		stage.style.position = 'absolute';
		stage.style.width = '100%';
		stage.style.height = '100%';
		stage.style.margin = '0px';
		stage.style.padding = '0px';
		stage.style.zIndex = '10000';
		stage.style.top = '0px';
		stage.style.left = '0px';

		stage.style.cursor = "url('images/easteregg/hammer.cur'), url('../images/easteregg/hammer.cur'), default";

		stage.onmousedown = function ()
		{
			stage.style.cursor = "url('images/easteregg/hammer2.cur'), url('../images/easteregg/hammer2.cur'), default";
		}

		stage.onmouseup = function ()
		{
			stage.style.cursor = "url('images/easteregg/hammer.cur'), url('../images/easteregg/hammer.cur'), default";
		}
		
		// Fetch our window size
		document.body.appendChild (stage);
		
		Website.easteregg.stage = $(stage);
		
		// Let's show the logo!
		Website.easteregg.showLogo 
		(
			function ()
			{
				Website.easteregg.showManual
				(
					Website.easteregg.startGame
				)
			}
		);
	},
	
	'showLogo' : function (afterFinish)
	{
		// Create e logo div
		var logo = $(document.createElement ('h1'));
		logo.innerHTML = 'The Secret Easter Egg';
		logo.style.color = 'black';
		
		logo.hide ();
		Website.easteregg.stage.appendChild (logo);
		
		logo.style.fontSize = '50px';
		
		logo.style.position = 'absolute';
		logo.style.top = ((Website.easteregg.stage.getHeight() / 2) - 50) + 'px';
		logo.style.left = ((Website.easteregg.stage.getWidth() / 2) - (logo.getWidth() / 2)) + 'px';
		
		Website.easteregg.stage.appendChild (logo);
		
		logo.appear 
		({

			'afterFinish' : function (div)
			{
				div.element.fade
				({
					'afterFinish' : function ()
					{
						afterFinish();
					}
				});
			}
		});
	},
	
	'showManual' : function (afterFinish)
	{
		// Create e logo div
		var logo = $(document.createElement ('p'));
		logo.innerHTML = 'Click the red square 10 times!';
		
		logo.hide ();
		Website.easteregg.stage.appendChild (logo);
		
		logo.style.fontSize = '30px';
		
		logo.style.position = 'absolute';
		logo.style.top = ((Website.easteregg.stage.getHeight() / 2) - 50) + 'px';
		logo.style.left = ((Website.easteregg.stage.getWidth() / 2) - (logo.getWidth() / 2)) + 'px';
		logo.style.color = 'black';
		
		Website.easteregg.stage.appendChild (logo);
		
		logo.appear 
		({
			'afterFinish' : function (div)
			{
				div.element.fade
				({
					'afterFinish' : function ()
					{
						afterFinish();
					}
				});
			}
		});
	},
	
	'startGame' : function ()
	{
		Website.easteregg.square = document.createElement ('div');
		Website.easteregg.square.style.position = 'absolute'
		Website.easteregg.square.style.width = '50px';
		Website.easteregg.square.style.height = '50px';
		Website.easteregg.square.style.background = 'red';
		Website.easteregg.square.onclick = Website.easteregg.moveSquare;
		Website.easteregg.square.className = 'easteregg_clickgame_square';
		
		Website.easteregg.stage.appendChild (Website.easteregg.square);
		
		Website.easteregg.counter = 0;
		
		var myDate=new Date();
		Website.easteregg.startDate = myDate;
		
		Website.easteregg.moveSquare ();
	},
	
	'moveSquare' : function ()
	{
		var left = Math.random() * (Website.easteregg.stage.getWidth() - 50);
		var top = Math.random() * (Website.easteregg.stage.getHeight() - 50);

		Website.easteregg.square.style.left = Math.ceil(left) + 'px';
		Website.easteregg.square.style.top = Math.ceil(top) + 'px';

		if (Website.easteregg.counter < 10)
		{
			Website.easteregg.counter ++;
		}
		else
		{
			Website.easteregg.showScore ();
		}
	},
	
	'showScore' : function ()
	{
		Website.easteregg.square.style.display = 'none';
		
		var myDate = new Date();		
		var score = myDate - Website.easteregg.startDate;
		
		// Create e logo div
		var logo = $(document.createElement ('p'));
		logo.style.color = 'black';

		var rscore = Math.round((1 / score) * (Website.easteregg.stage.getHeight () * Website.easteregg.stage.getWidth ()));
		
		logo.innerHTML = 'You have won...<br /> Your score is <strong>'+rscore + '</strong><br />('+score+' milliseconds)';
		
		logo.hide ();
		Website.easteregg.stage.appendChild (logo);
		
		logo.style.fontSize = '30px';
		
		logo.style.position = 'absolute';
		logo.style.top = ((Website.easteregg.stage.getHeight() / 2) - 80) + 'px';
		logo.style.left = ((Website.easteregg.stage.getWidth() / 2) - (logo.getWidth() / 2)) + 'px';
		logo.style.textAlign = 'center';
		
		Website.easteregg.stage.appendChild (logo);
		
		logo.appear 
		({
			'afterFinish' : function (div)
			{
				div.element.fade
				({
					'duration' : 5,
					'afterFinish' : function ()
					{
						Website.easteregg.stage.style.display = 'none';
						Website.easteregg.stage.parentNode.removeChild (Website.easteregg.stage);
						Website.easteregg.afterFinish ();
					}
				});
			}
		});
	}
};
