function pathFilename(path) {
	var match = /\/([^\/]+)$/.exec(path);
	if (match) {
		return match[1];
	}
}

function getRandomInt(min, max) {
	// via https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Math/random#Examples
	return Math.floor(Math.random() * (max - min + 1)) + min;
}

function randomChoice(items) {
	return items[getRandomInt(0, items.length-1)];
}

var xkcd = {
	latest: null,
	last: null,
	cache: {},
	base: 'http://dynamic.xkcd.com/api-0/jsonp/comic/',

	get: function(num, success, error) {
		if (num == null) {
			path = '';
		} else if (Number(num)) {
			path = String(num);
		} else {
			error(false);
			return false;
		}
		
		if (num in this.cache) {
			this.last = this.cache[num];
			success(this.cache[num]);
		} else {
			return $.ajax({
				url: this.base+path,
				dataType: 'jsonp',
				success: $.proxy(function(data) {
					this.last = this.cache[num] = data;
					success(data);
				}, this),
				error: error});
		}
	}
};

TerminalShell.commands['sudo'] = function(terminal) {
	var cmd_args = Array.prototype.slice.call(arguments);
	cmd_args.shift(); // terminal
	if (cmd_args.join(' ') == 'make me a sandwich') {
		terminal.print('Okay.');
	} else {
		var cmd_name = cmd_args.shift();
		cmd_args.unshift(terminal);
		cmd_args.push('sudo');
		if (TerminalShell.commands.hasOwnProperty(cmd_name)) {
			this.sudo = true;
			this.commands[cmd_name].apply(this, cmd_args);
			delete this.sudo;
		} else if (!cmd_name) {
			terminal.print('sudo what?');
		} else {
			terminal.print('sudo: '+cmd_name+': command not found');
		}
	}
};

TerminalShell.filters.push(function (terminal, cmd) {
	if (/!!/.test(cmd)) {
		var newCommand = cmd.replace('!!', this.lastCommand);
		terminal.print(newCommand);
		return newCommand;
	} else {
		return cmd;
	}
});

TerminalShell.commands['shutdown'] = TerminalShell.commands['poweroff'] = function(terminal) {
	if (this.sudo) {
		terminal.print('Broadcast message from guest@resume');
		terminal.print();
		terminal.print('The system is going down for maintenance NOW!');
		return $('#screen').fadeOut();
	} else {
		terminal.print('Must be root.');
	}
};

TerminalShell.commands['logout'] =
TerminalShell.commands['exit'] = 
TerminalShell.commands['quit'] = function(terminal) {
	terminal.print('Bye.');
	$('#prompt, #cursor').hide();
	terminal.promptActive = false;
};

TerminalShell.commands['restart'] = TerminalShell.commands['reboot'] = function(terminal) {
	if (this.sudo) {
		TerminalShell.commands['poweroff'](terminal).queue(function(next) {
			window.location.reload();
		});
	} else {
		terminal.print('Must be root.');
	}
};

function linkFile(url) {
	return {type:'dir', enter:function() {
		window.location = url;
	}};
}

Filesystem = {
	'contact.info': {type:'file', read:function(terminal) {
		terminal.print($('<h4>').text('Mike Walker'));
		terminal.print('N Las Vegas, NV 89085');
		terminal.print('702.714.0629');
		terminal.print($('<p>').html('<a href="mailto:mike@mikewalker.info">mike@mikewalker.info</a>'));
	}},
        'qualifications.summary': {type:'file', read:function(terminal) {
		terminal.print();
		$.each([
			'5+ years of cross platform experience which include analyzing,',
			'installing, maintaining, troubleshooting, and repairing hardware,', 
			'software, networks, and peripheral and storage devices, at the consumer and enterprise level.',
			'',
			'Superior technical support and troubleshooting abilities as a result of a diverse computer background.',
			'',
			'Effectively used communication skills and technical knowledge to transform Wife into Linux power user.',
			'',
			'Technology early adopter and actively self studies new technologies.',
		], function(num, line) {
			terminal.print(line);
		});
        }},
	'skills.hardware': {type:'file', read:function(terminal) {
                terminal.print();
                $.each([
			'Dell PowerEdge Series Servers, HP ProLiant Series Servers, Sun Microsystems SPARC & x86 Servers, Fortinet FortiGate Firewalls, Dell PowerConnect Switches, Mailfoundry Anti-Spam, Sun StorEDGE Direct Attached Storage, Network Appliance NAS, LTO & DLT Tape Libraries, Miscellaneous PC/Apple Hardware, SCSI devices, Fiber Channel Devices.',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'skills.software': {type:'file', read:function(terminal) {
                terminal.print();
                $.each([
			'Microsoft Office Suite, Open Office Suite, Corel WordPerfect, BMC Remedy, Lotus Notes, Attachmate Reflection, EMC Networker Backup, Symantec Backup Exec, Symantec Antivirus, McAfee Antivirus, Apache/Tomcat Webserver, IIS Webserver, Microsoft Active Directory, Microsoft Exchange 2000/2003, VMware ESX Server, KVM Virtual Server, Oracle xVM VirtualBox, Citirx, Asterisk, FreePBX, Trixbox, Nagios, QuickBooks, Postfix. ',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'skills.languages': {type:'file', read:function(terminal) {
                terminal.print();
                $.each([
			'C++, HTML, Unix Shell Scripting in Bash/Bourne-Again Shell, SH/Borune Shell, KSH/Korn Shell.',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'skills.operatingsystems': {type:'file', read:function(terminal) {
                terminal.print();
                $.each([
			'Windows 2000/2003/NT/XP/Vista/7, DOS, Solaris 7/8/9/10 x86 & SPARC, OpenSolaris, RedHat Linux, CentOS Linux, OSX Leopard/Snow Leopard, Ubuntu Linux, HP-UX, IRIX, Unix.',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'skills.networking': {type:'file', read:function(terminal) {
                terminal.print();
                $.each([
			'SMTP, DNS, DHCP, VPN, TCP/IP, FTP, Samba, Telnet, SSH, Cabling.',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'education.bachelors': {type:'file', read:function(terminal) {
                terminal.print();
                $.each([
			'Cleveland State University – Cleveland, OH',
			'Bachelor of Science in Computer and Information Science – August 2006',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'experience.zappos': {type:'file', read:function(terminal) {
		terminal.print($('<h4>').text('Zappos.com – Henderson, NV'));
                terminal.print();
                $.each([
			'System Administrator, May 2011 – Present',
			'',
			'Work in Progress! :-D',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'experience.cardplayermedia': {type:'file', read:function(terminal) {
		terminal.print($('<h4>').text('Card Player Media – Las Vegas, NV'));
                terminal.print();
                $.each([
			'System Administrator, June 2009 – April 2011',
			'',
			'Responsible for all desktops and servers in environment',
			'Install, Configure, and Maintain Production and Development LAMP servers (CentOS/Apache/mySQL/PHP)',
			'Work on call and off business hours to ensure uptime',
			'Established new backup procedures to manage company data',
			'Managed Asterisk VOIP Phone system',
			'Installed and configured Nagios system monitoring system to proactively monitor system health',
			'Managed Active Directory, VPN, DNS, and Exchange Email on Windows 2003 Server systems',
			'Introduced virtual machine solutions to shrink server footprint and reduce operating cost',
			'Standardized workstation and server configuration',
			'Provided support and configuration of BlackBerry, Android, and iOS devices',
			'Proactively tested and maintained UPS backups to protect systems against power problems',
			'Provided remote support for traveling employees',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'experience.bechtelsaic': {type:'file', read:function(terminal) {
		terminal.print($('<h4>').text('Bechtel SAIC Co. – Las Vegas, NV'));
                terminal.print();
                $.each([
                        'Unix / Linux System Administrator, Oct 2006 – March 2009',
			'Unix Operations Intern, June 2005 – Sept 2005',
			'Unix Operations Intern, June 2004 – Sept 2004',
			'',
			'Responsible for 50 enterprise class Unix and Linux Servers.',
			'Work 24 hour on call schedule, two weeks per month, to provide support for mission critical applications.',
			'Knowledge of NIS user authentication environment.',
			'Proficient in command line administration, including the use of vi, ed, grep, and other Unix tools.',
			'Compiled applications from source to include custom configuration, as necessary.',
			'Migrated legacy servers to virtual environments to increase availability and decrease operating cost.',
			'Provide user account maintenance support to Customer Service Help Desk.',
			'Actively monitor server system logs to identify potential problems or hardware failures.',
			'Backup and restore enterprise data using EMC Legato Networker software.',
			'Evaluate Operating System patches and bug fixes for their relevancy to the environment and deploy as necessary.',
			'Work with hardware vendors to diagnose and repair physical hardware problems.',
			'Utilize shell script programming to automate administration tasks.',
			'Research new technologies and methods to improve the server environment.',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'experience.lazorpoint': {type:'file', read:function(terminal) {
                terminal.print($('<h4>').text('Lazorpoint Co. – Cleveland, OH'));
                terminal.print();
                $.each([
                        'Client Services Engineer, May 2006 – Oct 2006',
			'',
			'Provided telephone and on site support to clients.',
			'Analyzed and evaluated client servers and workstations for necessary patches and bug-fixes.',
			'Configured and installed SoHo and enterprise level networking and firewall equipment.',
			'Repaired and upgraded client server and workstation hardware.',
			'Managed client user accounts in Microsoft Active Directory and Microsoft Exchange.',
			'Maintained application configuration for use over Citrix WAN connections.',
			'Provided support for client BlackBerry and Windows Mobile devices.',
			'Deployed new server and workstation hardware.',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
        'experience.circuitcity': {type:'file', read:function(terminal) {
                terminal.print($('<h4>').text('Circuit City – Mayfield Heights, OH'));
                terminal.print();
                $.each([
                        'Lead PC Services Technician, Oct 2004 – May 2006',
			'',
			'Performed repair and diagnostics of consumer PC and peripheral devices.',
			'Installed and configured new hardware and software.',
			'Utilized computer skills and knowledge to troubleshoot consumer PC problems and errors.',
			'Removed viruses and other malicious software.',
			'Acted as a subject matter expert for the sales staff to answer specific computer questions.',
			'Used Linux tools to migrate and recover data.',
			'Demonstrated communication skills by directly interacting with customers.',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
        'professionalmemberships.sixsigma': {type:'file', read:function(terminal) {
                terminal.print($('<h4>').text('Six Sigma Yellow Belt, – Sept 2008'));
                terminal.print();
                $.each([
			'Trained to use Six Sigma methodology to solve business problems and improve business results by identifying, measuring and eliminating defects and errors in existing processes and procedures.',
                ], function(num, line) {
                        terminal.print(line);
                });
        }},
	'references.txt': {type:'file', read:function(terminal) {
                terminal.print('Available Upon Request.');
        }},
	'welcome.txt': {type:'file', read:function(terminal) {
		terminal.print($('<h4>').text('Welcome to Mike Walker\'s resume console.'));
		terminal.print('Use "ls", "cat", and "cd" to navigate the filesystem.');
	}},
	'license.txt': {type:'file', read:function(terminal) {
		terminal.print($('<p>').html('Client-side logic for Wordpress CLI theme :: <a href="http://thrind.xamai.ca/">R. McFarland, 2006, 2007, 2008</a>'));
		terminal.print($('<p>').html('jQuery rewrite and overhaul :: <a href="http://www.chromakode.com/">Chromakode, 2010</a>'));
		terminal.print();
		$.each([
			'This program is free software; you can redistribute it and/or',
			'modify it under the terms of the GNU General Public License',
			'as published by the Free Software Foundation; either version 2',
			'of the License, or (at your option) any later version.',
			'',
			'This program is distributed in the hope that it will be useful,',
			'but WITHOUT ANY WARRANTY; without even the implied warranty of',
			'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the',
			'GNU General Public License for more details.',
			'',
			'You should have received a copy of the GNU General Public License',
			'along with this program; if not, write to the Free Software',
			'Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.'
		], function(num, line) {
			terminal.print(line);
		});
	}}
};
Filesystem['linkedin'] = linkFile('http://www.linkedin.com/in/walkerma');
Filesystem['email'] = linkFile('mailto:mike@mikewalker.info');
TerminalShell.pwd = Filesystem;

TerminalShell.commands['cd'] = function(terminal, path) {
	if (path in this.pwd) {
		if (this.pwd[path].type == 'dir') {
			this.pwd[path].enter(terminal);
		} else if (this.pwd[path].type == 'file') {
			terminal.print('cd: '+path+': Not a directory');
		}
	} else {
		terminal.print('cd: '+path+': No such file or directory');
	}
};

TerminalShell.commands['dir'] =
TerminalShell.commands['ls'] = function(terminal, path) {
	var name_list = $('<ul>');
	$.each(this.pwd, function(name, obj) {
		if (obj.type == 'dir') {
			name += '/';
		}
		name_list.append($('<li>').text(name));
	});
	terminal.print(name_list);
};

TerminalShell.commands['cat'] = function(terminal, path) {
	if (path in this.pwd) {
		if (this.pwd[path].type == 'file') {
			this.pwd[path].read(terminal);
		} else if (this.pwd[path].type == 'dir') {
			terminal.print('cat: '+path+': Is a directory');
		}
	} else if (pathFilename(path) == 'alt.txt') {
		terminal.setWorking(true);
		num = Number(path.match(/^\d+/));
		xkcd.get(num, function(data) {
			terminal.print(data.alt);
			terminal.setWorking(false);
		}, function() {
			terminal.print($('<p>').addClass('error').text('cat: "'+path+'": No such file or directory.'));
			terminal.setWorking(false);
		});
	} else {
//		terminal.print('You\'re a kitty!');
		terminal.print('Meow.');
	}
};

TerminalShell.commands['rm'] = function(terminal, flags, path) {
	if (flags && flags[0] != '-') {
		path = flags;
	}
	if (!path) {
		terminal.print('rm: missing operand');
	} else if (path in this.pwd) {
		if (this.pwd[path].type == 'file') {
			delete this.pwd[path];
		} else if (this.pwd[path].type == 'dir') {
			if (/r/.test(flags)) {
				delete this.pwd[path];
			} else {
				terminal.print('rm: cannot remove '+path+': Is a directory');
			}
		}
	} else if (flags == '-rf' && path == '/') {
		if (this.sudo) {
			TerminalShell.commands = {};
		} else {
			terminal.print('rm: cannot remove /: Permission denied');
		}
	}
};

TerminalShell.commands['wget'] = TerminalShell.commands['curl'] = function(terminal, dest) {
	if (dest) {
		terminal.setWorking(true);
		var browser = $('<div>')
			.addClass('browser')
			.append($('<iframe>')
					.attr('src', dest).width("100%").height(600)
					.one('load', function() {
						terminal.setWorking(false);
					}));
		terminal.print(browser);
		return browser;
	} else {
		terminal.print("Please specify a URL.");
	}
};

TerminalShell.commands['apt-get'] = function(terminal, subcmd) {
	if (!this.sudo && (subcmd in {'update':true, 'upgrade':true, 'dist-upgrade':true})) {
		terminal.print('E: Unable to lock the administration directory, are you root?');
	} else {
		if (subcmd == 'update') {
			terminal.print('Reading package lists... Done');
		} else if (subcmd == 'upgrade') {
			if (($.browser.name == 'msie') || ($.browser.name == 'firefox' && $.browser.versionX < 3)) {
				terminal.print($('<p>').append($('<a>').attr('href', 'http://abetterbrowser.org/').text('To complete installation, click here.')));
			} else {
				terminal.print('This looks pretty good to me.');
			}
		} else if (subcmd == 'dist-upgrade') {
			var longNames = {'win':'Windows', 'mac':'OS X', 'linux':'Linux'};
			var name = $.os.name;
			if (name in longNames) {
				name = longNames[name];
			} else {
				name = 'something fancy';
			}
			terminal.print('You are already running '+name+'.');
		} else if (subcmd == 'moo') {
			terminal.print('        (__)');
			terminal.print('        (oo)');
			terminal.print('  /------\\/ ');
			terminal.print(' / |    ||  ');
			terminal.print('*  /\\---/\\  ');
			terminal.print('   ~~   ~~  '); 
			terminal.print('...."Have you mooed today?"...');
		} else if (!subcmd) {
			terminal.print('This APT has Super Cow Powers.');
		} else {
			terminal.print('E: Invalid operation '+subcmd);
		}
	}
};

function oneLiner(terminal, msg, msgmap) {
	if (msgmap.hasOwnProperty(msg)) {
		terminal.print(msgmap[msg]);
		return true;
	} else {
		return false;
	}
}

TerminalShell.commands['man'] = function(terminal, what) {
	pages = {
		'last': 'Man, last night was AWESOME.',
		'help': 'Man, help me out here.',
		'next': 'Request confirmed; you will be reincarnated as a man next.',
		'cat':  'You are now riding a half-man half-cat.'
	};
	if (!oneLiner(terminal, what, pages)) {
		terminal.print('Oh, I\'m sure you can figure it out.');
	}
};

TerminalShell.commands['locate'] = function(terminal, what) {
	keywords = {
		'ninja': 'Ninja can not be found!',
		'keys': 'Have you checked your coat pocket?',
		'joke': 'Joke found on user.',
		'problem': 'Problem exists between keyboard and chair.',
		'raptor': 'BEHIND YOU!!!'
	};
	if (!oneLiner(terminal, what, keywords)) {
		terminal.print('Locate what?');
	}
};

Adventure = {
	rooms: {
		0:{description:'You are at a computer reading Mike Walker\s Resume.', exits:{west:1, south:10}},
		1:{description:'Life is peaceful there.', exits:{east:0, west:2}},
		2:{description:'In the open air.', exits:{east:1, west:3}},
		3:{description:'Where the skies are blue.', exits:{east:2, west:4}},
		4:{description:'This is what we\'re gonna do.', exits:{east:3, west:5}},
		5:{description:'Sun in wintertime.', exits:{east:4, west:6}},
		6:{description:'We will do just fine.', exits:{east:5, west:7}},
		7:{description:'Where the skies are blue.', exits:{east:6, west:8}},
		8:{description:'This is what we\'re gonna do.', exits:{east:7}},
		10:{description:'A dark hallway.', exits:{north:0, south:11}, enter:function(terminal) {
				if (!Adventure.status.lamp) {
					terminal.print('You are eaten by a grue.');
					Adventure.status.alive = false;
					Adventure.goTo(terminal, 666);
				}
			}
		},
		11:{description:'Bed. This is where you sleep.', exits:{north:10}},
		666:{description:'You\'re dead!'}
	},
	
	status: {
		alive: true,
		lamp: false
	},
	
	goTo: function(terminal, id) {
		Adventure.location = Adventure.rooms[id];
		Adventure.look(terminal);
		if (Adventure.location.enter) {
			Adventure.location.enter(terminal);
		}
	}
};
Adventure.location = Adventure.rooms[0];

TerminalShell.commands['look'] = Adventure.look = function(terminal) {
	terminal.print(Adventure.location.description);	
	if (Adventure.location.exits) {
		terminal.print();
		
		var possibleDirections = [];
		$.each(Adventure.location.exits, function(name, id) {
			possibleDirections.push(name);
		});
		terminal.print('Exits: '+possibleDirections.join(', '));
	}
};

TerminalShell.commands['go'] = Adventure.go = function(terminal, direction) {
	if (Adventure.location.exits && direction in Adventure.location.exits) {
		Adventure.goTo(terminal, Adventure.location.exits[direction]);
	} else if (!direction) {
		terminal.print('Go where?');
	} else if (direction == 'down') {
		terminal.print("On our first date?");
	} else {
		terminal.print('You cannot go '+direction+'.');
	}
};

TerminalShell.commands['light'] = function(terminal, what) {
	if (what == "lamp") {
		if (!Adventure.status.lamp) {
			terminal.print('You set your lamp ablaze.');
			Adventure.status.lamp = true;
		} else {
			terminal.print('Your lamp is already lit!');
		}
	} else {
		terminal.print('Light what?');
	}
};

TerminalShell.commands['sleep'] = function(terminal, duration) {
	duration = Number(duration);
	if (!duration) {
		duration = 5;
	}
	terminal.setWorking(true);
	terminal.print("You take a nap.");
	$('#screen').fadeOut(1000);
	window.setTimeout(function() {
		terminal.setWorking(false);
		$('#screen').fadeIn();
		terminal.print("You awake refreshed.");
	}, 1000*duration);
};

// No peeking!
TerminalShell.commands['help'] = TerminalShell.commands['halp'] = function(terminal) {
	terminal.print('That would be cheating!');
}; 

TerminalShell.fallback = function(terminal, cmd) {
	oneliners = {
		'make me a sandwich': 'What? Make it yourself.',
		'make love': 'I put on my robe and wizard hat.',
		'i read the source code': '<3',
		'pwd': 'You are in a maze of twisty passages, all alike.',
		'lpr': 'PC LOAD LETTER',
		'hello joshua': 'How about a nice game of Global Thermonuclear War?',
		'xyzzy': 'Nothing happens.',
		'date': 'March 32nd',
		'hello': 'Why hello there!',
		'who': 'Doctor Who?',
		'su': 'God mode activated. Remember, with great power comes great ... aw, screw it, go have fun.',
		'fuck': 'I have a headache.',
		'whoami': 'You are Richard Stallman.',
		'nano': 'Seriously? Why don\'t you just use Notepad.exe? Or MS Paint?',
		'top': 'It\'s up there --^',
		'moo':'moo',
		'ping': 'There is another submarine three miles ahead, bearing 225, forty fathoms down.',
		'find': 'What do you want to find? Mike Walker would be nice.',
		'hello':'Hello.',
		'more':'Oh, yes! More! More!',
		'your gay': 'Keep your hands off it!',
		'hi':'Hi.',
		'echo': 'Echo ... echo ... echo ...',
		'bash': 'You bash your head against the wall. It\'s not very effective.',
		'ssh': 'ssh, this is a library.',
		'uname': 'Commodore Amiga 500',
		'finger': 'Mmmmmm...',
		'kill': 'Terminator deployed to 1984.',
		'use the force luke': 'I believe you mean source.',
		'use the source luke': 'I\'m not luke, you\'re luke!',
		'serenity': 'You can\'t take the sky from me.',
		'enable time travel': 'Where we\'re going we don\'t need roads.',
		'ed': 'You are not a diety.'
	};
	oneliners['emacs'] = 'You should really use vim.';
	oneliners['vi'] = oneliners['vim'] = 'You have made the right choice.';
	
	cmd = cmd.toLowerCase();
	if (!oneLiner(terminal, cmd, oneliners)) {
		if (cmd == "asl" || cmd == "a/s/l") {
			terminal.print(randomChoice([
				'2/AMD64/Server Rack',
				'328/M/Transylvania',
				'6/M/Battle School',
				'48/M/The White House',
				'7/F/Rapture',
				'Exactly your age/A gender you\'re attracted to/Far far away.',
				'7,831/F/Lothlórien',
				'42/M/FBI Field Office'
			]));
		} else if  (cmd == "hint") {
			terminal.print(randomChoice([
 				'Use the source, Luke!',
 				'There are cheat codes.'
 			]));
		} else if (cmd == 'find kitten') {
			terminal.print($('<iframe width="800" height="600" src="http://www.robotfindskitten.net/rfk.swf"></iframe>'));
		} else if (/:\(\)\s*{\s*:\s*\|\s*:\s*&\s*}\s*;\s*:/.test(cmd)) {
			Terminal.setWorking(true);
		} else {
			$.get("/unixkcd/missing", {cmd: cmd});
			return false;
		}
	}
	return true;
};

var konamiCount = 0;
$(document).ready(function() {
	Terminal.promptActive = false;
	function noData() {
		Terminal.print($('<p>').addClass('error').text('Unable to load startup data. :-('));
		Terminal.promptActive = true;
	}
	$('#screen').bind('cli-load', function(e) {
		xkcd.get(null, function(data) {
			if (data) {
				xkcd.latest = data;
				$('#screen').one('cli-ready', function(e) {
					Terminal.runCommand('cat welcome.txt');
				});
				Terminal.runCommand('cat welcome.txt');
			} else {
				noData();
			}
		}, noData);
	});
	
	$(document).konami(function(){
		function shake(elems) {
			elems.css('position', 'relative');
			return window.setInterval(function() {
				elems.css({top:getRandomInt(-3, 3), left:getRandomInt(-3, 3)});
			}, 100);	
		}
		
		if (konamiCount == 0) {
			$('#screen').css('text-transform', 'uppercase');
		} else if (konamiCount == 1) {
			$('#screen').css('text-shadow', 'gray 0 0 2px');
		} else if (konamiCount == 2) {
			$('#screen').css('text-shadow', 'orangered 0 0 10px');
		} else if (konamiCount == 3) {
			shake($('#screen'));
		} else if (konamiCount == 4) {
			$('#screen').css('background', 'url(/unixkcd/over9000.png) center no-repeat');
		}
		
		$('<div>')
			.height('100%').width('100%')
			.css({background:'white', position:'absolute', top:0, left:0})
			.appendTo($('body'))
			.show()
			.fadeOut(1000);
		
		if (Terminal.buffer.substring(Terminal.buffer.length-2) == 'ba') {
			Terminal.buffer = Terminal.buffer.substring(0, Terminal.buffer.length-2);
			Terminal.updateInputDisplay();
		}
		TerminalShell.sudo = true;
		konamiCount += 1;
	});
});

