// Toggle the squirrel survey visibility on and off
function squirrel_showsurvey() {
	// Variables 
	var o = document.getElementById("hp_squirrelblurb")
	
	// Stupid ass HTML DOM doesn't pass the visibility until you've clicked the event
	// so check for empty visibility also, otherwise you need two clicks the first time
	if (o.style.display == "none" || o.style.display == "") { 
		visSquirrelRandBlurb = true
		document.getElementById("hp_squirrelChatter").style.display = "none"
		o.style.display = "block"
	} else {
		visSquirrelRandBlurb = false
		o.style.display = "none"
	}
}

// Function for submitting the retreiving ajax random question data
function callAjax() {
	var xmlHttp;
	try {	
		//alert ("1");
		xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
	}
	catch (e) {
		//alert ("catch1");
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
		}
		catch (e) {
			//alert ("catch2");
	    	try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				//alert ("catch4");
				alert("No AJAX!?");
				return false;
			}
		}
	}
	//alert ("2");
	xmlHttp.onreadystatechange = function() {
		//alert ("2.1");
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			//alert ("2.2");
			o = document.getElementById('hp_squirrelblurb_mid')
			//alert ("2.3");
			o.innerHTML = xmlHttp.responseText
			//alert ("2.4");
		}
	}
	//alert ("3");
	xmlHttp.open("GET","survey/fs_random.cfm",true);
	//alert ("4");
	xmlHttp.send(null);
	//alert ("5");
}

// Script waits a specific amount of time then changes the text
// in a div and hides/unhides it from view
function cycleBlurb(c,d) {
	//alert("cycleBlurb started")

	// Initializes the script and sets up the phrases that will display
	// Calls the toggleBlurb function which itself will loop

	// Variable assignments
	// Pass the o and d variables (strings) through to next function
	
	phrases = new Array()
	phrases[0] = "I love nuts as much as any squirrel, but seriously, the Moon landings were real."
	phrases[1] = "Step right up and punch a squirrel...wait, what?!"
	phrases[2] = "I can see your house from here! You should clean your gutters."
	phrases[3] = "Know anyone you want sent to the Moon? Against their will?"
	phrases[4] = "You know who I don't trust? Pigeons. They got the beady eyes."
	phrases[5] = "Watch out, that giant Moon might be preparing to attack!"
	phrases[6] = "What's up?  I got something for you if you just click here..."
	phrases[7] = "You can pet me, I won't bite."
	phrases[8] = "I'd be on Twitter if, ya know, I were a pigeon."
	phrases[9] = "Watch out, that giant Moon might be preparing to attack!"	
	phrases[10] = "Isn't that Moon upside down?"
	phrases[11] = "Come talk to me -- I'm bored up here!"
	phrases[12] = "C'mon, click me -- I dare you!"
	phrases[13] = "Have you seen my iPhone? I bet Galileo took it!"
	phrases[14] = "I'm not loony, just a little nutty."
	phrases[15] = "Where's the squirrel in the Moon?"
	phrases[16] = "No one up here but us lunatics."
	phrases[17] = "It's safe to come out; the werewolves have gone."
	phrases[18] = "Follow my Tweets! But don't call me a pigeon!"
	phrases[19] = "Who are you calling a rodent?"
	phrases[20] = "I am not a rat in a cuter coat, Sara Jessica!"
	phrases[21] = "When the moon hits your eye, like a nut in the sky...that's amore."
	phrases[22] = "I don't play sidekick to a Moose...that's my cousin."
	phrases[23] = "You can't send me to the Moon, I ain't no flying squirrel."	
	phrases[24] = "My favorite ballet...The Nutcracker"
	phrases[25] = "Preserve wildlife! Picket a squirrel!"
	phrases[26] = "You think squirrel is hard to say? Try eichhornchen. Isn't &quot;squirrel&quot; easier?"
	phrases[27] = "Send me presents."
	phrases[28] = "Squirrel. It's what's for dinner. Wait, what?!"
	phrases[29] = "Squirrels. What pigeons wish they were."
	phrases[30] = "I was the squirrel in &quot;Christmas Vacation&quot;."
	phrases[31] = "In terms of mass, you could send 169 squirrels into space versus one chimp!"
	phrases[32] = "169 squirrels can colonize the Moon faster than one chimp!"
	phrases[33] = "I'm freaking out, man! I'm freaking out!"
	phrases[34] = "Humans have a big toe, I have a big tail."
	phrases[35] = "A pigeon once referred to me as vermin.  He can only fly in circles now."
	phrases[36] = "Saw an African Pygmy squirrel on Nat Geo the other day.  Creeped me out."
	phrases[37] = "After those NASA missions, I told the Man in the Moon he was all wet!"
	phrases[38] = "How many nuts can a nutty squirrel chuck, if a nutty squirrel could chuck nuts?"
	phrases[39] = "Am I annoying you yet? How about now? Smile when you've had enough!"
	phrases[40] = "Watch out below!"
	phrases[41] = "LCROSS confirms lunar water but no nuts. What a let down."
	phrases[42] = "LCROSS finds enough water to drown a squirrel.  I think NASA's is scheming."
	
	
	toggleBlurb(c,d);
}
function toggleBlurb(c,d,l) {
	// Variables
	// Convert input strings to actual HTML DOM objects
	var container = document.getElementById(c)
	var div = document.getElementById(d)
		
	var durVis = Math.floor(Math.random()*15+10) * 1000
	var durHid = Math.floor(Math.random()*10+5) * 1000
	var index = Math.floor(Math.random()*41)
	var toggleBlurb_t1;
	var toggleBlurb_t2;
	
	// Process and do stuff here
	if (visSquirrelRandBlurb == false) {
		// Inserts a phrase from the array at random and then unhides the blurb
		div.innerHTML = phrases[index]
		container.style.display = "block"
	} else if (l != false) {
		// Hides the random phrase blurb in case something else hasn't already
		// Does not hide if l is passed as false, which happens when it's called from mouseover
		container.style.display = "none"
	}
	
	// Start looping but only if it's not being called by mouseover
	// Hides blurb after a set period of time
	// Displays the next blurb after another period of time running in parallel
	if (l != false || l == undefined) {
		var wait = durVis + durHid
		toggleBlurb_t1 = setTimeout("hideBlurb('hp_squirrelChatter')",durVis)
		toggleBlurb_t2 = setTimeout("toggleBlurb('hp_squirrelChatter','chatter')",wait)
	}
}
function hideBlurb(c) {
	var container = document.getElementById(c)
	container.style.display = "none"
}
