var cnnQuizAnswers = [
	{
		correct: 1,
		answer:	'Montana\'s Niners won it all in XVI, XIX, XXIII and XXIV.'
	},
	{
		correct: 3,
		answer:	'Lombardi owns a .750 career winning percentage.'
	},
	{
		correct: 2,
		answer:	'Aikman transferred from Oklahoma to UCLA after his freshman year.'
	},
	{
		correct: 3,
		answer:	'Riggins was selected sixth overall by the Jets in 1971.'
	},
	{
		correct: 2,
		answer:	'Green Bay defeated Kansas City 35-10 in Super Bowl I and Oakland 33-14 in Super Bowl II.'
	},
	{
		correct: 0,
		answer:	'Six wide receivers have won MVP honors: Hines Ward, Deion Branch, Desmond Howard, Jerry Rice, Fred Biletnikoff and Lynn Swann.'
	},
	{
		correct: 2,
		answer:	'White played two seasons with the Showboats before joining the NFL\'s Philadelphia Eagles.'
	},
	{
		correct: 3,
		answer:	'Dallas beat New York 31-28 in the season opener that year. Seattle beat New York 17-12 in Week 7.'
	},
	{
		correct: 0,
		answer:	'The World Championship Game Trophy was initially awarded to the winner of the AFL-NFL World Championship Game, which came to be called the Super Bowl when the AFL and NFL merged in 1970.'
	},
	{
		correct: 2,
		answer:	'Eric Mangini (Jets), Nick Saban (Dolphins) AND Romeo Crennel (Browns) all coached under Belichick.'
	}
];

var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var ver = navigator.appVersion; 
var MacPPC = (navigator.platform=='MacPPC') ? true : false;
var netscapeDOM = (document.layers) ? true : false;
var microsoftDOM = (document.all) ? true : false;
var geckoDOM = (document.getElementById && microsoftDOM != true) ? true : false;

if(geckoDOM) { netscapeDOM = false; microsoftDOM = false; }

var suppDHTML = ((bVer >= 4) && (netscapeDOM || microsoftDOM || geckoDOM)) ? true : false;

var hidestr = null;
var showstr = null;
var domstr = null;
var prestr = null;
var poststr = null;

if (microsoftDOM) { 

	hidestr = "hidden";
	showstr = "visible";
	prestr = "document.all.";
	poststr = ".style";
}
else if (netscapeDOM) { 

	hidestr = "hide";
	showstr = "show";
	prestr = "document.layers.";
	poststr = "";
	
}
else if (geckoDOM) {

	hidestr = "hidden";
	showstr = "visible";
	prestr = "document.getElementById('";
	poststr = "').style";	

}

var style_s = '<span class=\"bigRed\">';
var style_e = '<\/span>'

function writeToLayer(layername, isCorrect, writestring, nextQuestion ) {
	var results = '';

	results += '<table border="0" cellpadding="0" cellspacing="0" class="cnnAnswers">' + "\n";
	results += '<tr><td colspan="4"><img src="http://i.a.cnn.net/si/magazine/specials/bowlbash/2007/images/trivia/answer_t.gif" alt="SI.com - 2007 Bowl Bash" border="0" width="481" height="5"/></td></tr>' + "\n";
	results += '<tr>' + "\n";
	results += '<td rowspan="2" class="left"><img src="http://i.cnn.net/si/images/1.gif" width="8" height="1" border="0" alt=""/></td>' + "\n";
	if( isCorrect ) {
		results += '<td class="cnnArrow"><img src="http://i.a.cnn.net/si/magazine/specials/bowlbash/2007/images/trivia/arrow_g.gif" alt="" border="0" width="26" height="26"/></td><td class="cnnCorrect">correct!</td>' + "\n";
	} else {
		results += '<td class="cnnArrow"><img src="http://i.a.cnn.net/si/magazine/specials/bowlbash/2007/images/trivia/arrow_r.gif" alt="" border="0" width="26" height="26"/></td><td class="cnnWrong">wrong!</td>' + "\n";
	}
	results += '<td rowspan="2" class="right"><img src="http://i.cnn.net/si/images/1.gif" width="53" height="1" border="0" alt=""/></td>' + "\n";
	results += '</tr>' + "\n";
	results += '<tr><td class="cnnResult" colspan="2">' + writestring + '</td></tr>' + "\n";
	results += '<tr><td colspan="4"><img src="http://i.a.cnn.net/si/magazine/specials/bowlbash/2007/images/trivia/answer_b.gif" alt="SI.com - 2007 Bowl Bash" border="0" width="481" height="5"/></td></tr>' + "\n";
	results += '</table>' + "\n";

	writestring = results;
	writestring += '<div class="cnnSubmit"><a href="#" onclick="goNextQuestion( ' + nextQuestion + ' );"><img src="http://i.a.cnn.net/si/magazine/specials/bowlbash/2007/images/trivia/next.gif" alt="" border="0" width="133" height="29"/></a></div>';
	if(microsoftDOM) { 
		eval(prestr + layername).innerHTML = writestring;
	}
	else if(netscapeDOM) {
		eval(prestr + layername).document.open();
		eval(prestr + layername).document.writeln(writestring);
		eval(prestr + layername).document.close();
	}
	else if(geckoDOM) {
		document.getElementById(layername).innerHTML = writestring;
	}

}

var numRightOnFirstAttempt = 0;
if( queryString( 'correctOnOne' ) != "false" ) numRightOnFirstAttempt = queryString( 'correctOnOne' );
var fileName = ( ( ( window.location.pathname ).substr( 1 ) ).split( "/" ) )[ ( ( ( window.location.pathname ).substr( 1 ) ).split( "/" ) ) .length - 1 ];
var quesNumber  = 1 * fileName.substring( fileName.indexOf( '.' ) + 1, fileName.indexOf( '.', fileName.indexOf( '.' ) + 1 ) );
var numAttempted = 1;

function goNextQuestion(which) {
	if( which == 11 ) {
		location.href = "results.html?questionNum="+quesNumber+"&correctOnOne="+numRightOnFirstAttempt;
	} else {
		location.href = "content."+which+".html?questionNum="+quesNumber+"&correctOnOne="+numRightOnFirstAttempt;
	}
}

function checkAnswer() {
	
	var correctnum = cnnQuizAnswers[quesNumber-1].correct;
	var radioButtons = document.forms['quiz'].radioGroup;
	
	for ( var i = 0; i < radioButtons.length; i++ ) {
		if ( radioButtons[i].checked ) {
			if (radioButtons[i].value == correctnum) {
				if (numAttempted == 1) numRightOnFirstAttempt++;
				writeToLayer( 'answer', true, cnnQuizAnswers[quesNumber-1].answer, quesNumber + 1 );
			}
			else {
				numAttempted++;
				writeToLayer( 'answer', false, cnnQuizAnswers[quesNumber-1].answer, quesNumber + 1 );
			}

		}
	
	}
	
}

function pageQuery( q ) {
	if( q.length > 1 ) this.q = q.substring( 1, q.length );
	else this.q = null;
	this.keyValuePairs = new Array();
	if( q ) {
		for( var i = 0; i < this.q.split( "&" ).length; i++ ) {
			this.keyValuePairs[i] = this.q.split( "&" )[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function( s ) {
		for( var j = 0; j < this.keyValuePairs.length; j++ ) {
			if( this.keyValuePairs[j].split( "=" )[0] == s )
			return this.keyValuePairs[j].split( "=" )[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array( this.getLength() );
		for( var j = 0; j < this.keyValuePairs.length; j++ ) {
			a[j] = this.keyValuePairs[j].split( "=" )[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString( key ){
	var page = new pageQuery( window.location.search ); 
	return unescape( page.getValue( key ) ); 
}
