function switchstyle()
{
	if(window != top)
	{
		document.body.className = "peacebrothers";
	}
	else
	{
		document.body.className = "normal";
	}
}

/*
var allNormalWords = [
	"abortion", "absolute", "academy", "apocalypse", "account", "acid", "active",
	"activist", "activity", "adapter", "address", "admiration", "adult", "advance",
	"advantage", "advent", "affiliation", "agenda", "agent", "ahead", "air",
	"aircraft", "airship", "airtight", "alarm", "alcohol", "alkaline", "allergy",
	"alphabet", "always", "amateur", "ambulance", "anarchy", "anatomy", "ancestor",
	"anchor", "angel", "another", "antenna", "antimatter", "antique", "anxiety",
	"anywhere", "apartment", "apparently", "appear", "apprize", "aquarium",
	"aristocrat", "army", "article", "assembly", "assistant", "assurance",
	"astride", "atmosphere", "attack", "attitude", "attraction", "attention",
	"august", "bad", "balloon", "barbarian", "base", "bases", "battery", "beast",
	"bee", "beer", "begin", "beginner", "between", "bite", "black", "bless",
	"blue", "bordello", "boredom", "braindead", "brainwash", "break", "breakfast",
	"briefcase", "brochure", "brutal", "budget", "bull", "bunker", "bury", "cage",
	"camera", "captain", "car", "carbon", "carcass", "carting", "cartridge",
	"catastrophic", "cathedral", "centuries", "cerebration", "ceremony",
	"chainsaw", "challenge", "chaos", "charge", "cheat", "chopper", "church",
	"climate", "clock", "close", "cloudberry", "cobweb", "cockatrice", "coffee",
	"colonel", "combination", "common", "compact", "compatible", "compression",
	"computer", "concrete", "condition", "conditioner", "confirm", "confusion",
	"conquered", "conquest", "court", "creature", "credit", "creep", "crew",
	"cross", "currant", "current", "customer", "dangerous", "dawn", "dazzle",
	"death", "decay", "decoy", "defense", "degree", "democratic", "demon",
	"dentist", "description", "deserving", "desire", "despair", "destruction",
	"detective", "develop", "diplomacy", "dielectric", "diesel", "difference",
	"differences", "dimmer", "direction", "disband", "disc", "disco", "discord",
	"disfavor", "dishonest", "disk", "diskette", "disloyal", "distress",
	"distribution", "diva", "dive", "divide", "divorce", "Donald", "donkey",
	"downstairs", "dracula", "dread", "dreamer", "duck", "dynamite", "earthquake",
	"east", "economy", "ecotype", "ecstatic", "electricity", "electrode",
	"electron", "electronic", "elegant", "element", "elementary", "elephant",
	"elevator", "eliminate", "empire", "energetic", "engineer", "epidemic",
	"epilogue", "equal", "equipment", "erotic", "error", "essay", "estimate",
	"ethereal", "ethics", "evening", "exam", "example", "export", "expression",
	"extract", "eye", "fact", "factor", "fakir", "falcon", "family", "fantasy",
	"February", "feeling", "feminism", "feminist", "festival", "fetch", "feudal",
	"fight", "filament", "fireman", "firestation", "firing", "flame", "flat",
	"flatter", "float", "flood", "floor", "flute", "food", "forces", "foreground",
	"foreplay", "foretaste", "foreword", "formulate", "forward", "fossil",
	"fracture", "frigate", "fruit", "function", "funeral", "gabble", "gallery",
	"gallon", "gangster", "garage", "gene", "general", "generalize", "gentleman",
	"geometry", "ghost", "gliding", "glove", "glow", "gold", "goose", "government",
	"grade", "graphic", "grass", "grave", "gray", "graze", "green", "grind",
	"grinding", "grow", "grownup", "grumble", "guillotine", "hall", "hamburger",
	"hard", "harmless", "harmony", "hawk", "hazardous", "hazy", "hectare",
	"helicopter", "hell", "heresy", "hesitate", "highway", "highwire", "hobby",
	"homework", "honey", "honeymoon", "hook", "hovercraft", "humanity",
	"humiliating", "humorist", "hygienic", "hysteric", "icon", "iconoclast",
	"ideal", "identity", "idiot", "idol", "idyllic", "illusion", "illustrator",
	"immortal", "import", "income", "indicator", "indirect", "infiltration",
	"information", "injure", "ink", "inquisition", "insist", "inspiring",
	"institute", "instruments", "insulin", "insult", "intention", "interactive",
	"Internet", "intersect", "interview", "intruder", "invent", "invert", "iron",
	"irony", "island", "jacket", "jog", "joke", "judgment", "July", "keen",
	"keyword", "killer", "kilt", "kingdom", "larger", "lawyer", "lazy", "leech",
	"lick", "life", "lifelong", "lifestyle", "light", "like", "live", "lobby",
	"lowland", "lunatic", "lunch", "lure", "lynx", "mad", "magazine", "magpie",
	"mammoth", "man", "manipulation", "marginal", "marine", "masquerade",
	"massacre", "master", "material", "max", "maybe", "medal", "medium",
	"memorize", "mental", "mercury", "mercy", "Mickey", "microwave", "midnight",
	"military", "milk", "milky", "minor", "miserably", "misfortune", "model",
	"moment", "monoxide", "moose", "more", "morning", "mosquito", "mouse",
	"movement", "movie", "my", "myself", "mysterious", "nailgun", "nakedness",
	"name", "narcotic", "nastiness", "nasty", "natural", "nervous", "net",
	"nethack", "new", "newspaper", "nobility", "noble", "north", "northeast",
	"northwest", "nostalgic", "notion", "novice", "nugget", "nuthouse", "object",
	"occasion", "on", "only", "open", "orange", "organic", "originally", "own",
	"paddle", "paper", "paralysis", "paralyzed", "pardon", "pea", "pearl", "peer",
	"penetration", "performer", "perhaps", "period", "personal", "phantom",
	"philosophize", "phobia", "phone", "physical", "pickpocket", "pike",
	"pineapple", "pink", "planet", "plant", "poison", "police", "politics",
	"populous", "portrait", "possibly", "post", "poster", "premonition", "present",
	"president", "priority", "proceed", "profit", "progress", "prologue",
	"promote", "promotion", "prophylactic", "protection", "provide", "publishing",
	"purchase", "pursuit", "puss", "puzzle", "quest", "question", "racial",
	"radiation", "rash", "ravenous", "raw", "reach", "reasonable", "recall",
	"recently", "recognize", "recover", "red", "reflect", "rejuvenation",
	"relaxed", "representation", "repulsive", "rescue", "resigned", "responsible",
	"revive", "ridge", "rifle", "rolling", "rubber", "rubber-boots", "sale",
	"sand", "scale", "scar", "scatter", "schedule", "scientific", "scorn",
	"Scotland", "seal", "seeker", "sense", "sensitive", "sensor", "sensuous",
	"separate", "separator", "sergeant", "service", "setup", "shame", "shawl",
	"shell", "shine", "shipwreck", "shooting", "shotgun", "showdown",
	"sightseeing", "sign", "signature", "silver", "simulation", "situation",
	"size", "sketch", "skirt", "slim", "smell", "smile", "smooth", "solitary",
	"somebody", "source", "south", "southeast", "southwest", "space", "Spanish",
	"special", "specialist", "specter", "speculation", "speed", "spider",
	"spoiled", "spook", "squirrel", "staff", "star", "states", "steed", "step",
	"sterility", "stink", "storehouse", "street", "structure", "student",
	"submarine", "sue", "suicide", "sun", "sunglasses", "sunset", "supercharger",
	"support", "sweat", "swindler", "Switzerland", "table", "tea", "teacher",
	"tease", "teaser", "techno", "teeth", "temperature", "territory", "test",
	"Texas", "that", "then", "theory", "there", "thief", "thin", "time", "toilet",
	"tool", "toothbrush", "tooth", "tornado", "toupee", "trace", "transaction",
	"transmission", "treasure", "trick", "tutorial", "twilight", "umbrella",
	"uncle", "underwear", "underworld", "united", "unlimited", "unpleasant",
	"untrained", "unusual", "Usenet", "valuable", "values", "vampire", "vitality",
	"volatile", "wander", "warehouse", "warning", "waste", "wavelength", "waves",
	"way", "weak", "west", "where", "white", "wig", "willing", "wingspan",
	"withdraw", "wolverine", "woman", "worldwide", "worse", "wound", "yellow",
	"yesterday", "you", "zone"
];
*/

var allNormalWords = [
	"about", "actually", "add", "afk", "after", "again", "against", "ago", "ahh",
	"aim", "all", "almost", "alone", "alpha", "already", "also", "always", "and",
	"another", "any", "anymore", "anyone", "anything", "anyway", "are", "arf",
	"argh", "around", "ask", "attack", "away", "awesome", "back", "bad", "bah",
	"balance", "balanced", "base", "because", "been", "before", "behind", "being",
	"best", "better", "big", "bind", "bit", "blub", "blue", "boom", "boring",
	"bot", "both", "bots", "bougo", "brb", "break", "broken", "btw", "bug", "but",
	"bye", "call", "called", "camp", "camper", "campers", "camping", "can",
	"can't", "cap", "caps", "capture", "care", "cause", "change", "changed",
	"cheat", "check", "clan", "close", "code", "come", "command", "console",
	"cool", "could", "course", "crap", "crylink", "ctf", "cya", "damn", "darn",
	"day", "defend", "defense", "did", "didn't",
	"die", "different", "does", "doesn't", "doh", "doing", "done",
	"don't", "down", "download", "downloading", "dude", "dunno", "easy",
	"else", "end", "enemy", "english", "enough", "even", "ever", "every",
	"everyone", "eyes", "facing", "fail", "fair", "far", "fast", "faster", "feel",
	"few", "ffs", "finally", "find", "fine", "first", "fix", "fixed", "flag",
	"for", "found", "fps", "frag", "frags", "free", "friend", "from",
	"full", "fun", "funny", "game", "games", "german", "get", "getting", "give",
	"god", "going", "gone", "gonna", "good", "got", "gotta", "great", "gtg",
	"guess", "gun", "guy", "guys", "had", "haha", "hahaha", "hai",
	"happens", "hard", "has", "hate", "have", "health", "heh", "hehe", "hell",
	"hello", "help", "here", "he's", "hey", "high", "him", "his", "hit",
	"hmm", "hook", "how", "huh", "idea", "idiot", "i'll", "i'm", "indeed",
	"instead", "into", "isn't", "its", "it's", "i've", "jlue", "job",
	"join", "joined", "jump", "jumping", "just", "keep", "key", "keys",
	"kick", "kill", "killed", "kind", "kinda", "know", "lag", "laggy", "lags",
	"laser", "last", "late", "later", "lava", "learn", "least", "leave", "left",
	"less", "let", "let's", "level", "like", "little", "lmao", "long",
	"look", "looks", "lost", "lot", "love", "low", "luck", "lucky", "made", "make",
	"makes", "man", "many", "map", "maps", "master", "match", "may", "maybe",
	"mean", "means", "meh", "middle", "might", "minutes", 
	"mod", "mode", "more", "most", "mouse", "move", "much", "music",
	"must", "nah", "name", "need", "needs", "never", "new", "nex", "next",
	"nexuiz", "nice", "night", "nobody", "non", "noo", "noob", "noobs", "nooo",
	"nope", "normal", "not", "nothing", "now", "off", "okay", "old", "omg",
	"once", "one", "ones", "only", "oops", "opbai", "open", "other", "others",
	"ouch", "our", "out", "over", "own", "part", "people", "ping", "place", "play",
	"played", "player", "players", "playing", "please", "pls", "plz", "point",
	"points", "portal", "portals", "possible", "pow", "power", "ppl", "press",
	"pretty", "probably", "problem", "put", "quad", "quite", "race",
	"radar", "read", "real", "really", "reason", "record", "red", "reds",
	"remember", "restart", "right", "rocket", "rofl", "ronan", "room", "round",
	"run", "running", "said", "same", "saw", "say", "score", "scoreboard",
	"scores", "sec", "second", "seconds", "see", "seems", "seen", "server",
	"servers", "set", "shield", "shoot", "shooting", "shot", "should", "show",
	"side", "since", "slow", "small", "sniper", "some", "someone",
	"something", "sometimes", "somewhere", "soon", "sorry", "sound", "sounds",
	"space", "spawn", "speak", "spec", "speed", "sry", "start", "still", "stop",
	"strange", "stuff", "stupid", "such", "suck", "sucks", "sure", "swfy",
	"switch", "take", "talking", "team", "teammates", "teams", "teleporter",
	"tell", "test", "than", "thank", "thanks", "that", "that's", "the",
	"their", "them", "then", "there", "there's", "these", "they", "thing",
	"things", "think", "this", "those", "though", "thought", "through", "thx",
	"time", "times", "today", "too", "took", "top", "tried", "true", "try",
	"trying", "turn", "two", "type", "unbalanced", "unconnected", "understand",
	"unfair", "use", "used", "using", "vcall", "version", "very", "vote", "voted",
	"wait", "wall", "walls", "wanna", "want", "wanted", "was", "watch",
	"water", "way", "weapon", "weapons", "weird", "well", "were", "what",
	"what's", "when", "where", "which", "while", "who", "why",
	"will", "win", "winning", "with", "without", "won", "wonder", "wont", "won't",
	"work", "works", "would", "wow", "wrong", "wtf", "xsax", "yay", "yea", "yeah",
	"yep", "yes", "yet", "you", "your", "you're", "yup"
];

var allSpecialWords = [
	"lol",
	"brlogenshfegle",
	"honorificabilitudinitatibus"
];

var WORDS_TO_USE = 128;

var wordsTypedList = [];
var wordsLeft = [];
var currentWord = "";
var wordsTyped = 0;
var charsTyped = 0;
var startTime = null;
var mistakes;
var keys;

var jsform, typearea;

function clearStatus()
{
	jsform.mistakes.value = "";
	jsform.wordsleft.value = "";
	jsform.wpm.value = "";
	jsform.cpm.value = "";
	typearea.innerHTML = "";
}

function updateStatus()
{
	if(!startTime)
	{
		clearStatus();
		return;
	}

	jsform.mistakes.value = mistakes;
	jsform.wordsleft.value = wordsLeft.length;
	jsform.wpm.value = wordsTyped * 60000 / (new Date().getTime() - startTime.getTime());
	jsform.cpm.value = charsTyped * 60000 / (new Date().getTime() - startTime.getTime());

	var h = "";
	for(var i in wordsTypedList)
		h += "<span class=" + wordsTypedList[i].c + ">" + wordsTypedList[i].w + "</span> ";

	h += "<span class=thisword>" + currentWord + "</span> ";

	for(var i in wordsLeft)
		h += "<span class=nextword>" + wordsLeft[i] + "</span> ";

	typearea.innerHTML = h;
}

function initTest()
{
	mistakes = 0;
	startTime = new Date();
	wordsLeft = [].concat(allSpecialWords);
	wordsTypedList = [];

	var normalWords = [].concat(allNormalWords);
	while(wordsLeft.length < WORDS_TO_USE - 4) // minus 3 for ballmer mode
	{
		var w = Math.floor(Math.random() * normalWords.length);
		wordsLeft.push(normalWords[w]);
		normalWords.splice(w, 1);
	}

	// shuffle them around
	for(var i = 0; i < wordsLeft.length; ++i)
	{
		var j = Math.floor(Math.random() * (wordsLeft.length - i)) + i;
		var w = wordsLeft[i];
		wordsLeft[i] = wordsLeft[j];
		wordsLeft[j] = w;
	}

	// ballmer mode
	wordsLeft.splice(Math.floor(Math.random() * (wordsLeft.length + 1)), 0, "developers", "developers", "developers", "developers");

	wordsTyped = 0;
	charsTyped = 0;
}

function nextWord()
{
	currentWord = wordsLeft[0];
	wordsLeft.splice(0, 1);
}

function finished()
{
	currentWord = "";
	updateStatus();
	alert("your score is:\n" + jsform.wpm.value + " wpm\n" + jsform.cpm.value + " cpm\n\nyou made:\n" + jsform.mistakes.value + " mistakes");

	jsform.word.value = "hit space to start again";
	startTime = null;
}

function reinsert(currentWord)
{
	var r;
	for(;;)
	{
		r = Math.floor(Math.random() * (wordsLeft.length + 1));
		if(r > 0 && r < wordsLeft.length && wordsLeft[r] == "developers" && wordsLeft[r-1] == "developers") // never kill ballmer
			continue;
		wordsLeft.splice(r, 0, currentWord);
		break;
	}
}

function checkWord()
{
	jsform = document.getElementById("jsform");
	typearea = document.getElementById("typearea");

	if(startTime == null)
	{
		initTest();
		nextWord();
		updateStatus();
		jsform.word.value = "";
		keys = 0;
	}
	else
	{
		w = jsform.word.value.replace(/ /g, "");
		if(w == "")
		{
			jsform.word.value = "";
			keys = 0;
		}
		else
		{
			if(w == currentWord)
			{
				if(keys >= currentWord.length)
				{
					// register the word
					++wordsTyped;
					wordsTypedList.push({ w: w, c: "oldword" });
					charsTyped += w.length + 1;
				}
				else
				{
					// clipboard cheater :P
					++mistakes;
					reinsert(currentWord);
					wordsTypedList.push({ w: w, c: "oldcheatword" });
				}
			}
			else
			{
				// register the mistake
				++mistakes;
				reinsert(currentWord);
				wordsTypedList.push({ w: w, c: "oldwrongword" });
			}
			if(wordsLeft.length > 0)
			{
				nextWord();
				updateStatus();
				jsform.word.value = "";
				keys = 0;
			}
			else
				finished();
		}
	}

	jsform.word.focus();

	return false;
}

function checkSpace(e)
{
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) // IE
		keynum = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		keynum = e.which;
	if(keynum == 32)
	{
		checkWord();
		return false;
	}
	else
	{
		++keys;
		return true;
	}
}

