// Preload Images
red = new Image();
red.src = "./poohsticks/stix_red.gif";

blue = new Image();
blue.src = "./poohsticks/stix_blue.gif";

var players = new Array("Roo", "Kanga", "Owl", "Rabbit", "Eeyore", "Tigger",
		"Piglet", "Christopher Robin", "Winnie-the-Pooh")

var playerinfo = new Array(
	"He's small and cute, but he's not a very good\n"
	+ "player. You should be able to overcome him\n"
	+ "easily.",
	"Roo's mom is better than he is, but she's still\n"
        + "not a great player.",
	"Wise he may be, but he's no stick thrower.",
	"He usually spends more time in his vegetable\n"
	+ "garden than he does playing Poohsticks.",
	"Although forgetful about his tail, and often\n"
	+ "too depressed to play a good game, he can be\n"
	+ "a tough opponent.",
	"The bouncy, fun, average-at-Poohsticks kind of\n"
	+ "guy",
	"Always found playing Poohsticks with Mr. Edward\n"
	+ "Bear, so he's really quite good.",
        "As Pooh's best friend, Christopher Robin has\n"
        + "played a lot of Pooh sticks.\n"
        + "Watch it, this guy is good!",
	"Pooh is the inventor of the game, and quite\n"
	+ "possibly the best player in all of the 100\n"
	+ "Akre Wood. Take him on at your peril.\n"
	+ "A mighty champion!"
)

var opponent = -1

function prob(playerID) {
	return (playerID + 1) / 10
}

function winAgainst(playerID) {
	var chance, actual
	chance = 1 - prob(playerID)
	actual = Math.random()
	if (actual < chance)
		return true
	else
		return false
}

function newOpponent(selection) {
	var chosen = selection.selectedIndex - 1
	var mugshot = document.poohSTIX.mugshot
	var details = document.poohSTIX.details

	switch (chosen) {
		case -1: mugshot.src = "./poohsticks/poohsticks2.jpg"
			break;
		case 0: mugshot.src = "./others/roo_sign.jpg"
			break;
		case 1: mugshot.src = "./others/kanga_sign.jpg"
			break;
		case 2: mugshot.src = "./others/wol_sign.jpg"
			break;
		case 3: mugshot.src = "./others/rabbit_sign.jpg"
			break;
		case 4: mugshot.src = "./others/eeyore_sign.jpg"
			break;
		case 5: mugshot.src = "./others/tigger_sign.jpg"
			break;
		case 6: mugshot.src = "./others/piglet_sign.jpg"
			break;
		case 7: mugshot.src = "./others/chrisrob_balloon.jpg"
			break;
		case 8: mugshot.src = "./others/pooh_sign.jpg"
			break;
	}
	if (chosen == -1)
		details.value = details.defaultValue
	else
		details.value = players[chosen] + ":\n"
			+ playerinfo[chosen]
	opponent = chosen;
}

function playPoohSticks() {
	document.poohSTIX.result.value='';
	if (opponent == -1) {
		alert("You forgot to select an opponent!")
		return;
	}
	if(winAgainst(opponent)) {
		document.poohSTIX.result.value = 
			"Congratulations! "
			+ "You won against " + players[opponent]
			+ ".";
		document.poohSTIX.anim.src = eval("red.src");
	} else {
		document.poohSTIX.result.value = 
			"Sorry, "
                        + players [opponent] + " beat you.";
		document.poohSTIX.anim.src = eval("blue.src");
	}
	
}
