// Rune Javascript
// By David Lambert

function buttonPressed()
{
	word=document.getElementById("wordBox").value
	if (word.length==0)
		switch(parseInt(Math.random()*40))
		{
			case 1:
				word="Beer Beer Beer Tiddly Beer"
				break
			case 2:
				word="Sons of Fenrir"
				break
			case 3:
				word="Swords of Dalriada"
				break
			case 4:
				word="Mjolnir"
				break
			case 5:
				word="Pottsy Was here"
				break
			case 6:
				word="Falconer"
				break
			case 7:
				word="Valknut"
				break
			case 8:
				word="Odin"
				break
			case 9:
				word="Lupercal"
				break
			case 10:
				word="Einherjar"
				break
			default:
				word="Viking Runes"
				break
		}

 	parseName(word)
}

function clearMe()
{
	document.getElementById("wordBox").value=""
}

function allRunes()
{
	document.getElementById("runes").innerHTML="<h3>Freyja's &AElig;tt</h3>"
	addRune("f")
	addRune("u")
	addRune("th")
	addRune("a")
	addRune("r")
	addRune("k")
	addRune("g")
	addRune("w")
	document.getElementById("runes").innerHTML=document.getElementById("runes").innerHTML+"<h3>Heimdalls's &AElig;tt</h3>"
	addRune("h")
	addRune("n")
	addRune("i")
	addRune("j")
	addRune("ei")
	addRune("p")
	addRune("z")
	addRune("s")
	document.getElementById("runes").innerHTML=document.getElementById("runes").innerHTML+"<h3>Tyr's &AElig;tt</h3>"
	addRune("t")
	addRune("b")
	addRune("e")
	addRune("m")
	addRune("l")
	addRune("ng")
	addRune("d")
	addRune("o")
}

function parseName(word)
{
 	word=word.toLowerCase()
 	document.getElementById("runes").innerHTML=""
 	if (word.length>60)
 		document.getElementById("runes").innerHTML="<h2>Too many letters</h2>This will slow down your computer too much."
 	else
	while (word.length>0)
	{
		switch(word.substr(0,2))
		{

			case "ei":
				addRune("ei")
				word=word.substr(2)
				break
			case "ng":
				addRune("ng")
				word=word.substr(2)
				break
			case "th":
				addRune("th")
				word=word.substr(2)
				break
			case "qu":
				addRune("k")
				addRune("w")
				word=word.substr(2)
				break
			default:
				switch(word.charAt(0))
				{
				case " ":
					document.getElementById("runes").innerHTML=document.getElementById("runes").innerHTML+"<br>"
				break
				case "c":
					addRune("k")
					break
				case "q":
					addRune("k")
					break
				case "v":
					addRune("w")
					break
				case "x":
					addRune("k")
					addRune("s")
					break
				case "y":
					addRune("j")
					break
				default:
					if (word.charCodeAt(0)>=97 && word.charCodeAt(0)<=122)
						addRune(word.charAt(0))
					else
						addRune("_")
					break
				}
				word=word.substr(1)
			break
		}
	}
}

function addRune(runeInititals)
{
	document.getElementById("runes").innerHTML=document.getElementById("runes").innerHTML+"<img src=\"runes/"+runeInititals+".jpg\" onClick=\"facts(&quot;"+runeInititals+"&quot;)\" border=0 alt=\"image\">";
}

function checkEnter(e)
{
	var characterCode

	if(e && e.which)
	{
		e = e
		characterCode = e.which
	}
	else
	{
		e = event
		characterCode = e.keyCode
	}

	if(characterCode == 13)
		buttonPressed()
}

function facts(factsInitial)
{
	switch(factsInitial)
	{
		// First AEtt
		case "f":
			document.getElementById("descheader").innerHTML="<img src=\"runes/f.jpg\"><h2>Fehu - Rune of Wealth</h2>Associated with the god Njord. This rune represents the letter F."
		break
		case "u":
			document.getElementById("descheader").innerHTML="<img src=\"runes/u.jpg\"><h2>Uruz - Rune of Aurochs</h2>Associated with the giant cow, Audhumla. This rune represents the letter U."
		break
		case "th":
			document.getElementById("descheader").innerHTML="<img src=\"runes/th.jpg\"><h2>Thurisaz - Rune of Thor</h2>Associated with the god Thor. This rune represents the sound TH."
		break
		case "a":
			document.getElementById("descheader").innerHTML="<img src=\"runes/a.jpg\"><h2>Ansuz - Rune of Odin</h2>Associated with the god Odin. This rune represents the letter A."
		break
		case "r":
			document.getElementById("descheader").innerHTML="<img src=\"runes/r.jpg\"><h2>Raidho - Rune of Journey </h2>Associated with the god Forseti. This rune represents the letter R."
		break
		case "k":
			document.getElementById("descheader").innerHTML="<img src=\"runes/k.jpg\"><h2>Kenaz - Rune of Light</h2>Associated with the goddess Freyja. This rune represents the letters K and C."
		break
		case "g":
			document.getElementById("descheader").innerHTML="<img src=\"runes/g.jpg\"><h2>Gebo - Rune of Gift</h2>Associated with the god Odin. This rune represents the letter G."
		break
		case "w":
			document.getElementById("descheader").innerHTML="<img src=\"runes/w.jpg\"><h2>Wunjo - Rune of Joy</h2>Associated with the goddess Freyja. This rune represents the letters W and V."
		break
		//Second AEtt
		case "h":
			document.getElementById("descheader").innerHTML="<img src=\"runes/h.jpg\"><h2>Hagalaz - Rune of Hail</h2>Associated with the giant Ymir. This rune represents the letter H."
		break
		case "n":
			document.getElementById("descheader").innerHTML="<img src=\"runes/n.jpg\"><h2>Naudhiz - Rune of Need</h2>Associated with the Norns. This rune represents the letter N."
		break
		case "i":
			document.getElementById("descheader").innerHTML="<img src=\"runes/i.jpg\"><h2>Isa - Rune of Ice</h2>Associated with the Frost Giants. This rune represents the letter I."
		break
		case "j":
			document.getElementById("descheader").innerHTML="<img src=\"runes/j.jpg\"><h2>Jera - Rune of Year</h2>Associated with the god Frey. This rune represents the letters J and Y."
		break
		case "ei":
			document.getElementById("descheader").innerHTML="<img src=\"runes/ei.jpg\"><h2>Eihwas - Rune of Yew Tree</h2>Associated with the god Odin. This rune represents the sound EI."
		break
		case "p":
			document.getElementById("descheader").innerHTML="<img src=\"runes/p.jpg\"><h2>Perthro - Rune of Chance</h2>Associated with the Norns. This rune represents the letter P."
		break
		case "z":
			document.getElementById("descheader").innerHTML="<img src=\"runes/z.jpg\"><h2>Elhaz - Rune of Protection</h2>Associated with the Valkyries. This rune represents the letter Z."
		break
		case "s":
			document.getElementById("descheader").innerHTML="<img src=\"runes/s.jpg\"><h2>Sowilo - Rune of Sun</h2>Associated with the god Baldur. This rune represents the letter S."
		break
		//Second AEtt
		case "t":
			document.getElementById("descheader").innerHTML="<img src=\"runes/t.jpg\"><h2>Tiwaz - Rune of Tyr</h2>Associated with the god Tyr. This rune represents the letter T."
		break
		case "b":
			document.getElementById("descheader").innerHTML="<img src=\"runes/b.jpg\"><h2>Berkano - Rune of Birch Tree</h2>Associated with the goddess Frigg. This rune represents the letter B."
		break
		case "e":
			document.getElementById("descheader").innerHTML="<img src=\"runes/e.jpg\"><h2>Ehwas - Rune of Horse</h2>Associated with the god Frey. This rune represents the letter E."
		break
		case "m":
			document.getElementById("descheader").innerHTML="<img src=\"runes/m.jpg\"><h2>Mannaz - Rune of Man</h2>Associated with the god Heimdall. This rune represents the letter M."
		break
		case "l":
			document.getElementById("descheader").innerHTML="<img src=\"runes/l.jpg\"><h2>Laguz - Rune of Water</h2>Associated with the god Njord. This rune represents the letter L."
		break
		case "ng":
			document.getElementById("descheader").innerHTML="<img src=\"runes/ng.jpg\"><h2>Ingwaz - Rune of Frey</h2>Associated with the god Frey. This rune represents the sound NG."
		break
		case "d":
			document.getElementById("descheader").innerHTML="<img src=\"runes/d.jpg\"><h2>Dagaz - Rune of Day</h2>Associated with the god Odin. This rune represents the letter D."
		break
		case "o":
			document.getElementById("descheader").innerHTML="<img src=\"runes/o.jpg\"><h2>Othala - Rune of Ancestry</h2>Associated with the god Odin. This rune represents the letter O."
		break


		case "_":
			document.getElementById("descheader").innerHTML="<h2>Wyrd - Rune of Fate</h2>Blank rune associated with the god Odin. This rune represents uncertainty."
		break
	}
}

