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('Who was convinced that she was related to the royal family?');
 	questQuestion.setAnswer('Vera Duckworth');
	questQuestion.setPossibleAnsweres(new Array('Audrey Roberts','Vera Duckworth','Ivy Brennan'));
	questQuestions[i++] = questQuestion;
	
	

	var questQuestion = new QuestQuestion();
	questQuestion.setQuestion('Who baked Mavis and Derek Wilton\'s wedding cake in 1988?');
 	questQuestion.setAnswer('Percy Sugden');
	questQuestion.setPossibleAnsweres(new Array('Percy Sugden', 'Rita Fairclough', 'Victor Pendlebury'));
	questQuestions[i++] = questQuestion;
	

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion('Who went topless on the garage roof during a dispute with Mike Baldwin in 2002?');
 	questQuestion.setAnswer('Fiz Brown');
	questQuestion.setPossibleAnsweres(new Array('Fiz Brown', 'Karen McDonald', 'Ken Barlow'));
	questQuestions[i++] = questQuestion;

	
	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion('Who proudly claimed to have \"made gravy under shellfire\"?');
 	questQuestion.setAnswer('Percy Sugden');
	questQuestion.setPossibleAnsweres(new Array('Albert Tatlock', 'Vera Duckworth', 'Percy Sugden'));
	questQuestions[i++] = questQuestion;
	
	

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion('Why did Kevin and Sally Webster change their new daughter\'s name in 1994?');
 	questQuestion.setAnswer('Their daughter Rosie kept calling the baby \'Sophie\'');
	questQuestion.setPossibleAnsweres(new Array('Their daughter Rosie kept calling the baby \'Sophie\'', 'They wanted to confuse their friends', 'They couldn\'t spell their original choice'));
	questQuestions[i++] = questQuestion;
	
	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion('Who was the author of Weatherfield Yesterday, a history book published in 2000?');
 	questQuestion.setAnswer('Ken Barlow');
	questQuestion.setPossibleAnsweres(new Array('Kirk Sutherland', 'Kevin Webster', 'Ken Barlow'));
	questQuestions[i++] = questQuestion;
	
	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion('Whose son was originally played by Peter Noone of Herman\'s Hermits in 1961?');
 	questQuestion.setAnswer('Len Fairclough\'s');
	questQuestion.setPossibleAnsweres(new Array('Len Fairclough\'s', 'Jack and Annie Walker\'s', 'Elsie Tanner\'s'));
	questQuestions[i++] = questQuestion;
	

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion('To whom was Samir Rachid intending to donate a kidney when he was killed in 1995?');
 	questQuestion.setAnswer('Tracy Barlow');
	questQuestion.setPossibleAnsweres(new Array('Deirdre Rachid', 'Ken Barlow', 'Tracy Barlow'));
	questQuestions[i++] = questQuestion;
	

	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion('Who stole an engagement ring for his fiancee from a jeweller\'s shop in 2004?');
 	questQuestion.setAnswer('Kirk Sutherland');
	questQuestion.setPossibleAnsweres(new Array('Tyrone Dobbs', 'Kirk Sutherland', 'Jason Grimshaw'));
	questQuestions[i++] = questQuestion;
	


	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion('What colour was Elsie Tanner\'s hair?');
 	questQuestion.setAnswer('Red');
	questQuestion.setPossibleAnsweres(new Array('Blonde', 'Red', 'Brown'));
	questQuestions[i++] = questQuestion;



	var questQuestion = new QuestQuestion();	
	questQuestion.setQuestion('Where did Anne Malone meet her maker in 1998?');
 	questQuestion.setAnswer('In a freezer');
	questQuestion.setPossibleAnsweres(new Array('In a building society', 'In a freezer', 'In a department store'));
	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_container', {
			classNames : {
				toggle : 'vertical_accordion_toggle',
				toggleActive : 'vertical_accordion_toggle_active',
				content : 'vertical_accordion_content'
			}
		});
		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_container3', {
			classNames : {
				toggle : 'vertical_accordion_toggle',
				toggleActive : 'vertical_accordion_toggle_active',
				content : 'vertical_accordion_content'
			}
		});
		var nestedVerticalAccordion = new accordion('vertical_nested_container4', {
			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'
			}
		});
		var nestedVerticalAccordion = new accordion('vertical_nested_container6', {
			classNames : {
				toggle : 'vertical_accordion_toggle',
				toggleActive : 'vertical_accordion_toggle_active',
				content : 'vertical_accordion_content'
			}
		});
		var nestedVerticalAccordion = new accordion('vertical_nested_container7', {
			classNames : {
				toggle : 'vertical_accordion_toggle',
				toggleActive : 'vertical_accordion_toggle_active',
				content : 'vertical_accordion_content'
			}
		});

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

}
