/**
 * WhatInTheWorld
 * @class
 * @author grotter
 * @version 1.0
 */
WhatInTheWorld = function () {	
	/**
	 * Collect post data for AJAX call
	 * @public
	 * @param {Array} checked_radios Array of checked jQuery radio elements
	 */
	this.getPostData = function (checked_radios) {
		var post_data = {
			uid_choice: checked_radios.val(),
			uid_question: checked_radios.attr("name").replace("question_", ""),
			last_question_id: $("#last_question_id").text(),
			uid_quiz: $("#uid_quiz").text(),
			session_id: $("#session_id").text(),
			nav: "multiple_choice",
			action: "record_response"
		};
		
		return post_data;
	}
	
	/**
	 * Okay to progress
	 * @public
	 * @param {Object} myItem jQuery object of item container
	 * @returns {Boolean} Returns true if valid, false if not
	 */
	this.isValid = function (myItem) {
		return ($("input:checked", myItem).length > 0);
	}
	
	/**
	 * AJAX success callback, applied via Quiz.recordResponse method
	 * @public
	 * @param {String} data Server response string
	 * @param {String} textStatus Status code
	 */
	this.onSubmitSuccess = function (data, textStatus) {
		var div = $("<div />");
		div.html(data);
		if ($("#quiz_stats", div).length == 0) return;
		
		//Last question, populate the stats
		$("#num_correct").html($(".num_correct", div).text());
		$("#total_participants").html($(".total_participants", div).text());
		$("#avg_num_correct").html($(".avg_num_correct", div).text());
		$("#total_questions").html($(".quiz-image").length);
		
		//Extreme Mammals on the homepage needs some extra space, remove the last response
		if ($("#uid_quiz").text() == '12') {
			$(".quiz-stats").before("<h3>Done!</h3>");
			$(".correct").hide();
			$(".incorrect").hide();
		}
		
		if ($.browser.msie) {
			$("#num_correct, #total_questions, #total_participants").css("padding-right", "5px");
		}
	}
	
	/**
	 * Constructs the instance
	 * @constructs
	 */
	this.initialize = function () {
		var foo = new Quiz(this, "/module/whatintheworld/php/");
		//foo.setSize();
		foo.positionButtons();
		
		var scrollabe_api = $(".scrollable").scrollable({
			api: true,
			size: 1,
			clickable: false,
			keyboard: false,
			speed: 300
		});
		
		foo.setScrollableApi(scrollabe_api);		
		foo.initNavigation();
	}
};

$(document).ready(function () {
	var foo = new WhatInTheWorld();
	foo.initialize();
});

