function FlipSwitch(showMe){
	// create an array and loop through it to streamline
	// until then, brute force it.

	something = document.getElementById("action_message");
	something.style.visibility = "hidden";
	something = document.getElementById("inventory_message");
	something.style.visibility = "hidden";
	something = document.getElementById("quests_message");
	something.style.visibility = "hidden";
				
	// now make the selected one visible
	something = document.getElementById(showMe);
	something.style.visibility = "visible";
}

/* This is called when the html body loads */
function Initialize(){

	// default the action message
	FlipSwitch('action_message');
	// set focus to the textbox
	txtInput = document.getElementById("inputbox");
	txtInput.focus();
}
			
/* function where we take input and process it */
function ProcessInput(){

	// find that inputbox
	txtInput = document.getElementById("inputbox");

	// we try to get a handle on consequence
	txtConsequence = document.getElementById("consequence");

	// parse the command -- the convention is command parameters
	// thus we look for the first space as the command and the rest are params

	theWholeString = txtInput.value;

	firstSpace = theWholeString.indexOf(" ");

	// if there are no spaces, the command is the whole thing
	if(firstSpace == -1){ firstSpace = theWholeString.length; }

	// get the command substring from the whole string
	theCommand = theWholeString.substring(0, firstSpace);

	// get the parameters substring from the whole thing
	theParams = theWholeString.substring(firstSpace + 1);

	switch(theCommand){
		case "clear":
			// clear out the consequence screen
			txtConsequence.innerHTML = "";
			break;

		case "dict":
			txtConsequence.innerHTML += "<br />";
			GetDefinition(theParams);
			break;

		case "genex":
			txtMessage = ExcuseGenerator();
			// echo what was typed and add additional messages
			txtConsequence.innerHTML += "<br />" + txtMessage;
			break;

		case "h8ball":
			txtMessage = H8Ball(theParams);
			txtConsequence.innerHTML += "<br />" + txtMessage;
			break;

		case "kill":
			txtMessage = Kill(theParams);
			txtConsequence.innerHTML += "<br />" + txtMessage;
			break;

		case "hrm":
			txtMessage = HRM(theParams);
			txtConsequence.innerHTML += "<br />" + txtMessage;
			break;
	
		case "help":
			txtMessage = Help();
			txtConsequence.innerHTML += "<br />" + txtMessage;
			break;

		case "upupdowndownleftrightleftrightbastard":
			txtMessage = "Very Good! 1UP x 30";
			txtConsequence.innerHTML += "<br />" + txtMessage;
			break;

		case "0073735963":
			txtMessage = "If you insist.  Protect your ears.";
			txtConsequence.innerHTML += "<br />" + txtMessage;
			break;

		case "iddqd":
			txtMessage = "Godlike!";
			txtConsequence.innerHTML += "<br />" + txtMessage;
			break;

		
		default:
			txtMessage = theCommand + ": Command not found";
			// echo what was typed and add additional messages
			txtConsequence.innerHTML += "<br />" + txtMessage;
			break;
	}
	// then we clean up the textbox
	txtInput.value = "";

	// return false or else it will try to submit the darn thing
	return false;
}

function ExcuseGenerator(){
	var excuses = new Array();

	excuses[0] = "Power fluctuation due to electrical storm";
	excuses[1] = "Tectonic shift created an alteration in the magnetic field";
	excuses[2] = "AIMU readings negative";
	excuses[3] = "Gravitational instability";
	excuses[4] = "Unexpected reversal in boolean values";
	excuses[5] = "Syntax Error";
	excuses[6] = "General Protection Fault";
	excuses[7] = "Solar flares";
	excuses[8] = "Hamster died";
	excuses[9] = "AI needs psychiatric reevaluation";
	excuses[10] = "Tech needs psychiatric reevaluation";

	var randomNumber= Math.floor(Math.random() * excuses.length);

	return "Excuse #" + randomNumber + ": " + excuses[randomNumber];
}

function H8Ball(params){
	var answers = new Array();

	answers[0] = "Who cares?";
	answers[1] = "Signs point to hell no.";
	answers[2] = "Ask again never.";
	answers[3] = "I hate you";
	answers[4] = "Really?  It's that important to you?  No.  Just because you asked.";
	answers[5] = "There are no stupid questions but a LOT of inquisitive idiots.";
	answers[6] = "Run headfirst into a wall for only then will you receive enlightenment."
	
	var randomNumber= Math.floor(Math.random() * answers.length);

	return "Question: " + params + "<br />" + "Answer: " + answers[randomNumber];
}


function HRM(params){
	var max;
	var response;
	if(!isNaN(params)){
		max = 220 - params;
		response = "<em>Target Heart Rate For Age " + params + "</em><br />";
		response += "<em>Max:</em> " + max + "<br />";
		response += "<em>Moderate:</em> " + Math.round(max * .5) + " - " + Math.round(max * .7) + "<br />";
		response += "<em>Vigorous:</em> " + Math.round(max * .7) + " - " + Math.round(max * .85) + "<br />";
	} else {
		var response = "Parameter Error";
	}
	return response;
}

function Kill(params){
	var answers = new Array();

	answers[0] = "You take the blood, you take the life, you take them both and there you have the facts of knife!";
	answers[1] = "He was a Buffalo Sol-jah, Hitman Gunther.  Said he was fighting on arrival with his sniper rifle!";
	answers[2] = "Violence is never the answer...but like with multiple choice exams, we guess wrong once in a while.";
	answers[3] = "You got a problem?  I got a problem solver and its name is revolver -- Dr. Dre";
	answers[4] = "Those who claim that violence never solved anything never mentioned that bludgeoning someone makes for great stress relief.";
	answers[5] = "Guns don't kill people...but they sure help A LOT!";
	answers[6] = "You want me to do what?  No, I can't do that!  Well, not without Ave Maria playing in the background, anyway.";
	answers[7] = "Sure, I guess...but who's going to pay the dry cleaning bill?";
	answers[8] = "Ok, but I'll need a mallet, a Mickey Mouse costume, a bucket of birdseed, and a video camera to help with the insanity plea.";

	var randomNumber= Math.floor(Math.random() * answers.length);

	return "kill " + params + ":<br />" + answers[randomNumber];

}

function Help(){
	var commands = "";
	var linebreak = "<br />";
	commands += "<em>clear</em> -- clears the console screen";
	commands += linebreak;
	commands += "<em>dict word</em> -- uses an online dictionary to look up word";
	commands += linebreak;
	commands += "<em>genex</em> -- generate excuse";
	commands += linebreak;
	commands += "<em>h8ball question</em> -- Ask The Magic H8-Ball a question"
	commands += linebreak;
	commands += "<em>help</em> -- That's me!!!";
	commands += linebreak;
	commands += "<em>hrm age</em> -- Target Heart Rate";
	commands += linebreak;
	commands += "<em>kill</em> -- Um...terminate a process, I think.";
	commands += linebreak;

	return commands;
}

// shrink animation tests
/*
function shrink(){
	daScreen = document.getElementById("gamescreen");
	startWidth = daScreen.style.width;	
	for(i = 500; i > 0; i--){
		daScreen.style.width = i + "px";
	}
}
*/
