$(function(){
	// if($("div#testimonialContainer").length > 0) {
	// 	setInterval ( "testimonials.toggleTestomonials()", testimonials.delay );
	// }
})

var testimonials = {
	delay: 10000,	
	availableTestimonials: [1,2],
	toggleTestomonials: function() {
		var current = $("div[id^=testimonial_]:visible").attr('number');
		$("div[id^=testimonial_]:visible").slideUp("slow", function() {
			$.each(testimonials.availableTestimonials, function() {
				var selector = $("div#testimonial_" + this);
				if(current != this) { 
					selector.slideDown("slow");
					return;
				}
			})
		});
	}	
}

var quiz = {

	score: 0,
	position: 1,
	questions: new Array(),

	onSelectAnswer: function(question, correct_answer, option) {

		// If an answer has already been selected, the user cannot
		// choose another answer.
		if ($('#correct_text_' + question).is(':visible') || $('#incorrect_text_' + question).is(':visible')) {
			return;
		}

		// If the user was right, just highlight the correct answer.
		if (correct_answer) {
			$('#correct_text_' + question).slideDown("slow");
			this.score++;
		} else {
			// Mark all other options as wrong.
			$('#question_' + question).children().each(function(n) {
				if (n.id == 'incorrect_answer_' + question) {
					n.toggleClass('incorrect_answer_highlight');
				}
			});
			$('#incorrect_text_' + question).slideDown("slow");
		}

		// Highlight the correct answer.
		$('#correct_answer_' + question).toggleClass('correct_answer_highlight');

	},

	onShowNextQuestion: function(current_question) {

		// Show the first question if -1.
		if (current_question == -1) {
			$('#quiz_question_' + quiz.questions[0]).show();
			return;
		}

		// Hide the current question.
		$('#quiz_question_' + current_question).hide();

		// Show the next question.
		index = jQuery.inArray(current_question, this.questions)
		if (index != -1 && this.questions[index + 1] != undefined) {
			$('#quiz_question_' + quiz.questions[index + 1]).show();
			$('#current_position').empty();
			$('#current_position').append((this.position + 1) + "/" + this.questions.length);
		} else {
			// Show the final section.
			$('#current_score').empty();
			$('#current_score').append("" + this.score);
			$('#quiz_finished').show();
		}

		// Update the progress bar.
		this.updateProgressBar();

	},

	updateProgressBar: function() {
		new_width = (this.position / this.questions.length) * 100
		$('#prog-bar').css("width", new_width + '%');
		this.position++;
	}

}