window.addEvent('domready', function() {
	var textarea = $('launchBox');
		

	 
	
	// link is a basic function to redirect the page based on provided text.
	textarea.addEvents({
		focus: function() {
			// When focusing, if the textarea contains anything, clear it.
			//this is probably bad practice
			if (textarea.value.contains(textarea.value)) textarea.value = '';
		},
		
		keyup: function() {
			// When user keyups we check if there are any of the magic words.
			// If yes, we run the link event with the url of doc requested...
			if 	(textarea.value.contains('amsterdam')) textarea.fireEvent('link', './docs/security.html');
			//else if (textarea.value.contains('nearby')) textarea.fireEvent('link', './docs/london/');
			else if (textarea.value.contains('soup')) textarea.fireEvent('link', 'http://www.jorge.me.uk');
			else if (textarea.value.contains('help')) textarea.fireEvent('help');
			else if (textarea.value.contains('ok')) textarea.fireEvent('hideHelp');
			else if (textarea.value.contains('todo')) textarea.fireEvent('todo');
			// else if (textarea.value.contains('burn')) textarea.fireEvent('burn', 'fireEvent');
			// note that in case of 'delayed', we are firing the event 1 second late. kept for reference...
			// else if (textarea.value.contains('delayed')) textarea.fireEvent('burn', "I'm a bit late!", 1000);
		},
		
		link: function(text) {
			// When the textarea contains one of the magic words
			// set the window location to the url provided
			window.location = text;

		},
		
		help: function() {
			//loads the help doc into the help div
			$('help').load('./docs/help.html').set('tween', {duration: 'long'}).tween('background-color', '#fff380').start();
			//this should clear the textarea, ready for the user to type ok
			//doesn't work...
			$('launchBox').empty();
			
		},
		hideHelp: function() {
			//fades the help div out.
			$('help').fade('out').start();
			//again, doesn't work
			$('launchBox').empty();
		},
		todo: function() {
			//displays stuff i should do
			alert('* hint after 5s\n* style\n* eportfolios');
			$('launchBox').empty();
		}
	});
});
