function FitInterviewModule() {
}

FitInterviewModule.prototype.notificationsList = [Notifications.FIT_INTERVIEW_XML_LOADED];
FitInterviewModule.prototype.name = "FitInterviewModule";

FitInterviewModule.prototype.release = function() {

}

FitInterviewModule.prototype.handleNotification = function(notification, data) {

	switch (notification) {
		case Notifications.FIT_INTERVIEW_XML_LOADED:
			this.rawXML = data;
			this.xml = $(data);
			this.screenId = 0;
			this.screens = $("screen", this.xml);
			this.screenCount = this.screens.length;
			var template = this.type == "intro" ? "FitInterviewIntroContent" : "FitInterviewOutroContent";
			Phire.placeTemplate("#content", template + ".html #fit", $.callback(this, this.onInitScreens));
			break;

	}
}

FitInterviewModule.prototype.init = function(type) {

	this.type = type;
	log("****")
	Phire.placeTemplate("#content", (type == "intro" ? "FitInterviewIntro.html #fit" : "FitInterviewOutro.html #fit"), $.callback(this, this.onInit));
}
/************************************
 *  Start
 *************************************/

FitInterviewModule.prototype.onInit = function() {

	$("#fit_back").click(function() {
		Phire.sendNotification(Notifications.SHOW_MODULE, {
			module : "FitModule"
		});
	});
	$("#fit_start").click($.callback(this, function() {
		Phire.getModel("WebProxy").getInterviewXML(this.type);
	}));
	UserInfo.inTest = false;
	reloadImages();
}
/************************************
 *  Screens
 *************************************/

FitInterviewModule.prototype.onInitScreens = function() {
	$("#fit_next").click($.callback(this, this.onNext));
	$("#fit_back").click($.callback(this, this.onBack));
	$("#fit_print").click($.callback(this, this.onPrint));

	this.initProgressBar();

	this.nextScreen();
	UserInfo.inTest = true;
	reloadImages();
}

FitInterviewModule.prototype.initProgressBar = function() {
	var x = this.type == "intro" ? 234 : 295;
	var y = this.type == "intro" ? 416 : 421;

	for(var i = 1; i < this.screenCount; i++) {

		var symbol = $("<div id='fit_progress" + i + "' style='position:absolute; left:" + x + "px; top:" + y + "px; width:103px; height:12px; background-image:url(img/fit/progress_intro.jpg);'/> ");
		$("#fit_content").append(symbol);
		$(symbol).hide();
		x += 103;
	};
}

FitInterviewModule.prototype.nextScreen = function() {

	this.currentScreen = this.screens[this.screenId];
	var subline = $("head", this.currentScreen).text();
	var text = $("text", this.currentScreen).text();
	var image = $("image", this.currentScreen).text(); $("printable", this.currentScreen).text() == "0" ? $("#fit_print").hide() : $("#fit_print").show();

	$("#fit_image").css("background-image", "url(" + image + ")");
	$("#fit_subline").text(subline);
	$("#fit_text").scrollTop(0);

	$("#fit_text").html(text);

}

FitInterviewModule.prototype.onNext = function() {

	if(this.screenId == this.screenCount - 1) {

		Phire.sendNotification(Notifications.SHOW_ALERT_PANEL, {
			text : "Zurück zur Übersicht",
			ok : "OK",
			callback : function(value) {
				Phire.sendNotification(Notifications.SHOW_MODULE, {
					module : "FitModule"
				});
			}
		});
		return;
	}

	this.screenId++;
	$("#fit_progress" + this.screenId).show();
	this.nextScreen();

}

FitInterviewModule.prototype.onBack = function() {
	if(this.screenId == 0) {
		Phire.sendNotification(Notifications.EXIT_TEST, "FitModule");
		return;
	}
	$("#fit_next").show();
	$("#fit_progress" + this.screenId).hide();
	this.screenId--;
	this.nextScreen();
}

FitInterviewModule.prototype.onPrint = function() {

	$("#fit_text").jqprint({
		operaSupport : true,
		printContainer : false
	});

};

