//declares the state variable
var state

//defines the Init function, when run, it calls the main function.
function Init(){
main()

}

//defines the main function, which does tests random numbers stored in the variable test
//to decide what state Gordy will be in.  When it decided the state, it sets values for
//what Gordy says and thinks in the textboxes.
function main(){
var test = Math.random()
if (test <= .2) {
state = "provoked"
document.getElementById("main").setAttribute("src","provoked.jpg");
out.box.value = "..gr.. I want attention!!" 
thinks.responce.value = "rotten humans..."
}
if (test <= .15) {
state = "mad" 
document.getElementById("main").setAttribute("src","mad.jpg");
out.box.value = ".. GRRRR .. You had best run boy!!"
thinks.responce.value = "somebody stole my honey! grrr!!"
}
if (test <= .1) {
state = "sad" 
document.getElementById("main").setAttribute("src","sad.jpg");
out.box.value = "I want to hear some tunes..."
thinks.responce.value = "depression..depression..depression"
}
if (test <= .05) {
state = "hungry" 
document.getElementById("main").setAttribute("src","hungry.jpg");
out.box.value = "GORDY WANT RAVIOLI!"
thinks.responce.value = "mmmm food mmmm"
}
if (test > .2) {
state = "happy" 
setTimeout("Init()", 2000)
out.box.value = "..What a nice day.."
thinks.responce.value = "Gotta love those sunshine days!"
document.getElementById("main").setAttribute("src","happy.jpg");
}
}

//calls the starting fuction init.
Init()

//This fuction returns Gordy to a happy state when he is in a hungry state.
function feedgordy() {
if (state == "hungry") {
alert("Gordy loves ravioli")
state = "happy"
main() }
}

//This fuction returns Gordy to a happy state when he is in a provoked state.
function patgordy() {
if (state == "provoked") {
alert("Gordy loves to be pet")
state = "happy"
main() }
}

//This fuction returns Gordy to a happy state when he is in a mad state.
function rungordy() {
if (state == "mad") {
alert("Gordy cant attack a runner!")
state = "happy"
main() }
}

//This fuction returns Gordy to a happy state when he is in a sad state.
function singgordy() {
if (state == "sad") {
alert("Gordy likes to be sang to.")
state = "happy"
main() }
}

