
/* DAVE EDIT HERE */

var fully_awake_text = "Fantastic! You are fully awake in the marketplace. Chances are you have compelling eye-opening, visual communications.";
var awake_text = "Fantastic! You are awake in the marketplace. Chances are you have compelling eye-opening, visual communications.";
var alert_text = "You are alert but not fully awake in the marketplace. Chances are your target audience is overlooking you."
var asleep_text = "Wake up! You are asleep in the marketplace. Chances are your target audience is overlooking you and working with the competition.";
var fully_asleep_text = "Wake up! You are fully asleep in the marketplace. Chances are your target audience is overlooking you and working with the competition.";

/* STOP EDITING HERE */

var container_div = "center_col"; /*DIVISION TO FADE OUT  */
var theForm = "cognometer"; /*FORM TO SUBMIT INFO */
var resultsBox = "results_padding";
var resultsImage = "score_image"
var scoreBox = "score";
var resultsText = "advice";
var formFadeDur = 700;
var shrink_wrap = "content";

window.addEvent('domready', function() {
	$(theForm).addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop();
		
		//hides everything
		$(container_div).set('tween', {duration: formFadeDur});
		$(container_div).tween('opacity', 0);
		
		//calulates score
		var score = 0;
	    function add_radio_value(radio_array) {
			for(var i = 0; i < radio_array.length; i++) {
				if(radio_array[i].checked){
					score += parseInt(radio_array[i].value);	
				}
			}
		}
		
		add_radio_value($(theForm).q1);
		add_radio_value($(theForm).q2);
		add_radio_value($(theForm).q3);
		add_radio_value($(theForm).q4);
		add_radio_value($(theForm).q5);
		add_radio_value($(theForm).q6);
		add_radio_value($(theForm).q7);
		add_radio_value($(theForm).q8);
		add_radio_value($(theForm).q9);
		add_radio_value($(theForm).q10);
		var percent = (score*10)+"%";
		
		//inserts appropriate html for score
		
		if(score == 10){
		//you are fully awake
		$(resultsImage).set('class', 'awake');
		$(resultsText).set('html',fully_awake_text);	
		} else if(score > 7){
		//you are awake
		$(resultsImage).set('class', 'awake');
		$(resultsText).set('html',awake_text);
		} else if (score > 4) {
		 //you are alert
		$(resultsImage).set('class','alert');
		$(resultsText).set('html',alert_text);
		} else if(score > 0) {
		//you are asleep
		$(resultsImage).set('class', 'asleep');
		$(resultsText).set('html',asleep_text);
		} else {
		//you are fully asleep
		$(resultsImage).set('class', 'asleep');
		$(resultsText).set('html',fully_asleep_text);
		
		}
		$(scoreBox).set('html',percent);
		
		var shrink = function() {
		window.scrollTo(0,0);
		$(shrink_wrap).set('tween', {duration: formFadeDur+800});
		$(shrink_wrap).tween('height',340);
		
		}
		
		var show_results = function() {
			$(resultsBox).set('opacity',0);
			$(resultsBox).setStyle('display','block');
			$(resultsBox).fade('in');
		}
		
		
		
		shrink.delay(formFadeDur);
		//shows the results
		show_results.delay(formFadeDur+2000);
	});
});