var QuestQuestion = Class.create();

QuestQuestion.prototype = { 
 
 // Constructor 
 initialize: function(carouselElemID) { 
  	
  	this.question = "";
  	this.possibleAnsweres = "";
  	this.answer = "";
   
 },
 
 // Destructor
 destroy: function() {
 	   
 }, 
 setQuestion: function(question){ 
		this.question = question;
 }, 
 setAnswer: function(answer){ 
		this.answer = answer;
 },
 setPossibleAnsweres: function(possibleAnsweres){ 
 		this.possibleAnsweres = possibleAnsweres;
 },
 getAnswersAsHtml: function(){
 	
 		var answers = "<span id=\"sample_question_answer_one\">A: " + this.possibleAnsweres[0] + "</span>&nbsp;&nbsp;";
 		answers += "<span id=\"sample_question_answer_two\">B: " + this.possibleAnsweres[1] + "</span>&nbsp;&nbsp;";
 		answers += "<span id=\"sample_question_answer_three\">C: " + this.possibleAnsweres[2] + "</span>";
 		
 		return answers;
 },
 getIdsForWrongAnswers: function(){
 	
 	 var total = this.possibleAnsweres.length;
 	 
 	 var wrongAnswerIds = new Array();
 	 var i = 0;
 	 
 	 if(this.possibleAnsweres[0] != this.answer){
 	 
 	 	wrongAnswerIds[i++] = 'sample_question_answer_one';
 	 
 	 }
 	 
 	 if(this.possibleAnsweres[1] != this.answer){
 	 
 	 	wrongAnswerIds[i++] = 'sample_question_answer_two';
 	 
 	 }
 	 
 	 if(this.possibleAnsweres[2] != this.answer){
 	 
 	 	wrongAnswerIds[i++] = 'sample_question_answer_three';
 	 
 	 }
   
   return wrongAnswerIds;
 
 }
 
}

var QuestionSlideshow = Class.create();

QuestionSlideshow.prototype = {
 
 // Constructor 
 initialize: function(questQuestions) {
 
  	this.questQuestions = questQuestions;
  	
  	this.delayTime = 3;

		this.options = Object.extend({    
			test: 25
		}, arguments[1] || {});
		
		
    this.displayQuestion();

 },

 // Destructor
 destroy: function() {
 	   
 },
 displayQuestion: function(){
		
		
		Effect.Fade('sample_question_container_all',{duration: 1, afterFinish: this.showNewQuestion.bindAsEventListener(this)});
		
		 
 },
 showNewQuestion: function(){
 
 		
 		questionToInsert = this.getRandomQuestion();
 		
 		
 		$('sample_question_container_all_question').update(questionToInsert.question);		
 		
 		 
 		
 		$('sample_question_container_all_answers').update(questionToInsert.getAnswersAsHtml());
 		
 		
 		Effect.Appear('sample_question_container_all',{duration: 1});		
 		
 		
 		this.showAnswer.bindAsEventListener(this).delay(this.delayTime,questionToInsert);
 		
  
 },
 showAnswer: function(questionToInsert){ 
 		
 		
 		
 		
 		var wrongAnswerIds = questionToInsert.getIdsForWrongAnswers();
 		
 		try{
			new Effect.Parallel(
				[
					Effect.Fade(wrongAnswerIds[0],{from: 1.0, to: 0.3,duration: 1}),
					Effect.Fade(wrongAnswerIds[1],{from: 1.0, to: 0.3, duration: 1})
				],{afterFinish: (this.displayNextQuestion.bindAsEventListener(this)) }
			);
	  }catch(e){}

		
 
 },
 displayNextQuestion: function(){ 	
 	
 	this.displayQuestion.bindAsEventListener(this).delay(this.delayTime);
 
 }
 
 
 ,
 getRandomQuestion: function(){
		 
		var upperLimit = this.questQuestions.length;
 		
 		var rand_no = Math.floor((upperLimit)*Math.random()) + 1;
 		
		return this.questQuestions[rand_no - 1];
 }
}







//default funciton for all of the pages
function loadAllJs(){
	
	loadAccordions();
	
	
	var i = 0;
	var questQuestions = new Array();
	
	//add questions
	

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("How many hands does 'Big Ben' have?");
 	questQuestion.setAnswer('none');
	questQuestion.setPossibleAnsweres(new Array('none','one','two'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("Name the street in which the 'Great Fire of London' started.");
 	questQuestion.setAnswer('Pudding Lane');
	questQuestion.setPossibleAnsweres(new Array('Pudding Lane','Chandlers Lane','Brick Lane'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("Where was the German 'Enigma' code broken during World War II?");
 	questQuestion.setAnswer('Bletchley Park');
	questQuestion.setPossibleAnsweres(new Array('Bletchley Park','Gosford Park','Gatcombe Park'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("Which English football club's nickname is 'The Toffees'?");
 	questQuestion.setAnswer('Everton');
	questQuestion.setPossibleAnsweres(new Array('Arsenal','Everton','Aston Villa'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("What does 'by' mean in by-law?");
 	questQuestion.setAnswer('village');
	questQuestion.setPossibleAnsweres(new Array('old','village','through'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("Where did 'King John' supposedly lose the 'Crown Jewels' in the 13th century?");
 	questQuestion.setAnswer('The Wash');
	questQuestion.setPossibleAnsweres(new Array('Solent','The Wash','Bristol Channel'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("When the 'Lutine Bell' in Lloyds of London is sounded twice what does it mean?");
 	questQuestion.setAnswer('good news');
	questQuestion.setPossibleAnsweres(new Array('bad news','no news','good news'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("When was the 'Bank of England' established?");
 	questQuestion.setAnswer('1694');
	questQuestion.setPossibleAnsweres(new Array('1694','1794','1874'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("What was the first name of 'Inspector Morse' in the detective series of the same name?");
 	questQuestion.setAnswer('Endeavour');
	questQuestion.setPossibleAnsweres(new Array('Haslett','Endeavour','Joshua'));		
	questQuestions[i++] = questQuestion;

	/*
	this question is too long for the site, it does not display properly
	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("In 1989, a one year old black and white stray cat settled in the cabinet office in Whitehall and remained there until 1977. What was its name?");
 	questQuestion.setAnswer('Humphrey');
	questQuestion.setPossibleAnsweres(new Array('Humphrey','Henry','Harold'));		
	questQuestions[i++] = questQuestion;
	*/

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("In the 'Harry Potter' books by JK Rowling what was the name of the member of the school staff who had a boar hound called 'Fang'?");
 	questQuestion.setAnswer('Hagrid');
	questQuestion.setPossibleAnsweres(new Array('Dumbledore','Snape','Hagrid'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("Name the Royal English House represented by a white rose.");
 	questQuestion.setAnswer('York');
	questQuestion.setPossibleAnsweres(new Array('Lancaster','Windsor','York'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("What, according to Oscar Wilde, was the curse of the drinking classes?");
 	questQuestion.setAnswer('work');
	questQuestion.setPossibleAnsweres(new Array('incontinence','money','work'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("Name the ship sunk by a German U-boat on 7th May 1915.");
 	questQuestion.setAnswer('Lusitania');
	questQuestion.setPossibleAnsweres(new Array('Arcadia','Orsova','Lusitania'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("What day in April is 'St George's Day'?");
 	questQuestion.setAnswer('23rd');
	questQuestion.setPossibleAnsweres(new Array('23rd','24th','25th'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("What are 'Yeomen Warders' who guard the crown jewels popularly known as?");
 	questQuestion.setAnswer('Beefeaters');
	questQuestion.setPossibleAnsweres(new Array('Beefeaters','Ravens','Guardians'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("The current 'Football Association Cup' (FA Cup) was designed and made by which of the following?");
 	questQuestion.setAnswer('Italian jeweller in Bradford');
	questQuestion.setPossibleAnsweres(new Array('Russian jeweller in Manchester','Jewish jeweller in London','Italian jeweller in Bradford'));
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("What were the 'Bow Street Runners'?");
 	questQuestion.setAnswer('police force');
	questQuestion.setPossibleAnsweres(new Array('athletic team','police force','couriers'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("What was the name of the ship, commanded by 'Captain Scott', used on Scott's Antarctic expedition from 1901-1904?");
 	questQuestion.setAnswer('Discovery');
	questQuestion.setPossibleAnsweres(new Array('Pole Star','Discovery','Southern Cross'));		
	questQuestions[i++] = questQuestion;

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion("Who wrote the book for children entitled 'The Tale of Peter Rabbit'?");
 	questQuestion.setAnswer('Beatrix Potter');
	questQuestion.setPossibleAnsweres(new Array('Lewis Carroll','Beatrix Potter','Enid Blyton'));		
	questQuestions[i++] = questQuestion;
	
	

	
	var questionSlideshow = new QuestionSlideshow(questQuestions,{test:25});

	
}


/**
*In my case I want to load them onload, this is how you do it!
*/
Event.observe(window, 'load', loadAllJs, false);



//	Set up all accordions
function loadAccordions() {


	if($('vertical_container')){
  
		var bottomAccordion = new accordion('vertical_container');

		var nestedVerticalAccordion = new accordion('vertical_nested_container2', {
			classNames : {
				toggle : 'vertical_accordion_toggle',
				toggleActive : 'vertical_accordion_toggle_active',
				content : 'vertical_accordion_content'
			}
		});

		
		var nestedVerticalAccordion = new accordion('vertical_nested_container5', {
			classNames : {
				toggle : 'vertical_accordion_toggle',
				toggleActive : 'vertical_accordion_toggle_active',
				content : 'vertical_accordion_content'
			}
		});
		

		// Open first one
		bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
	}	

}