function MainModule() {
}

MainModule.prototype.notificationsList = [Notifications.LOGGED_IN, Notifications.LOG_OUT];
MainModule.prototype.name = "MainModule";

MainModule.prototype.release = function() {
	//Phire.removeTemplate("#mainmodule");

}

MainModule.prototype.handleNotification = function(notification, data) {

	switch (notification) {
		case Notifications.LOGGED_IN:
		case Notifications.LOG_OUT:
			this.checkLoggedIn();
			break;
	}
}

MainModule.prototype.init = function() {

	Phire.placeTemplate("#content", "MainModule.html #mainmodule", $.callback(this, this.onInit));

}

MainModule.prototype.initButton = function(id) {
	$(id).mouseover($.callback(this, this.mouseOver, id));
	$(id).mouseout($.callback(this, this.mouseOut, id));
	$(id).click($.callback(this, this.click, id));
	this.mouseOut("#mainmodule_jobtest");
	this.mouseOut("#mainmodule_feelWell");
	this.mouseOut("#mainmodule_fit");
	reloadImages();
}

MainModule.prototype.mouseOver = function(id) {

	$(id).css("color", "#000");

	switch(id) {
		case "#mainmodule_jobtest":
			$(id).css("background-image", "url(img/main_button1_rollover.jpg)");
			$("#mainmodule_content").css("background-image", "url(img/main_content2.jpg)");
			this.useFade ? $("#mainmodule_overlay_jobtest").fadeIn(300) : $("#mainmodule_overlay_jobtest").show();
			break;

		case "#mainmodule_feelWell":
			$(id).css("background-image", "url(img/main_button2_rollover.jpg)");
			$("#mainmodule_content").css("background-image", "url(img/main_content3.jpg)");
			this.useFade ? $("#mainmodule_overlay_feelWell").fadeIn(300) : $("#mainmodule_overlay_feelWell").show();
			break;

		case "#mainmodule_fit":
			$(id).css("background-image", "url(img/main_button3_rollover.jpg)");
			$("#mainmodule_content").css("background-image", "url(img/main_content4.jpg)");
			this.useFade ? $("#mainmodule_overlay_fit").fadeIn(300) : $("#mainmodule_overlay_fit").show();
			break;
	}

}

MainModule.prototype.mouseOut = function(id) {

	switch(id) {
		case "#mainmodule_jobtest":
			$(id).css("background-image", "url(img/main_button1_copy.jpg)");
			$("#mainmodule_overlay_jobtest").hide();

			break;

		case "#mainmodule_feelWell":
			$(id).css("background-image", "url(img/main_button2_copy.jpg)");
			$("#mainmodule_overlay_feelWell").hide();

			break;

		case "#mainmodule_fit":
			$(id).css("background-image", "url(img/main_button3_copy.jpg)");
			$("#mainmodule_overlay_fit").hide();
			break;
	}
	$(id).css("color", "#fff");
	$("#mainmodule_content").css("background-image", "url(img/main_content1.jpg)");
}

MainModule.prototype.click = function(id) {

	Phire.sendNotification(Notifications.NAVIGATE_TO, {
		nav : id
	});

}

MainModule.prototype.onInit = function() {

	var contentCSS = {
		"background-image" : "url(img/main_content1.jpg)",
		"background-repeat" : "no-repeat",
		"height" : "380px",
		"width" : "652px",
		"position" : "relative",
		"float" : "left"
	};
	var navCSS = {
		"text" : "url(img/main_content1.jpg)",
		"background-repeat" : "no-repeat",
		"height" : "84px",
		"width" : "670px",
		"font-weight" : "bolder",
		"line-height" : "18px",
		"font-size" : "18px",
		"text-align" : "center"
	};

	var nav1CSS = {
		"background-image" : "url(img/main_button1_copy.jpg)",
		"background-repeat" : "no-repeat",
		"width" : "216px",
		"height" : "84px",
		"float" : "left",
		"cursor" : "pointer",
		"padding" : "1.5em 0 0 0"

	};
	var nav2CSS = {
		"background-image" : "url(img/main_button2_copy.jpg)",
		"background-repeat" : "no-repeat",
		"width" : "213px",
		"height" : "84px",
		"float" : "left",
		"cursor" : "pointer",
		"padding" : "1.5em 0 0 0"
	};
	var nav3CSS = {
		"background-image" : "url(img/main_button3_copy.jpg)",
		"background-repeat" : "no-repeat",
		"width" : "223px",
		"height" : "84px",
		"float" : "left",
		"cursor" : "pointer",
		"padding" : "1em 0 0 0"
	};

	$("#mainmodule_overlay_jobtest").hide();
	$("#mainmodule_overlay_feelWell").hide();
	$("#mainmodule_overlay_fit").hide();

	$("#mainmodule_content").css(contentCSS);
	$("#mainmodule_nav").css(navCSS);
	$("#mainmodule_jobtest").css(nav1CSS);
	$("#mainmodule_feelWell").css(nav2CSS);
	$("#mainmodule_fit").css(nav3CSS);

	this.useFade = !(BrowserDetect.browser == "Explorer" && BrowserDetect.version < 9);

	this.initButton("#mainmodule_jobtest");
	this.initButton("#mainmodule_feelWell");
	this.initButton("#mainmodule_fit");

	$("#login_token").coolinput({
		blurClass : 'defaultTextActive',
		hint : 'Aktionscode eingeben'
	});

	$("#nav_member_login").click(function() {
		Phire.sendNotification(Notifications.SHOW_LOGIN_PANEL);
	});

	$("#login_token").keypress($.callback(this, function(e) {
		var code = e.keyCode ? e.keyCode : e.which;
		if(code == 13)
			this.validateToken();
	}))

	$("#nav_token_login").click($.callback(this, this.validateToken));

	//Check if already logged in
	this.checkLoggedIn();

	Phire.sendNotification(Notifications.NAV_STATE, "");

	$("#mainmodule_hint").hide();
	$("#nav_help").hover(function() {
		$("#mainmodule_hint").show();
	}, function() {
		$("#mainmodule_hint").hide();
	});
	UserInfo.inTest = false;

	$("#container").show();

	//Phire.getModel("WebProxy").loginUsingToken("val");
}

MainModule.prototype.validateToken = function() {
	var val = $("#login_token").val();
	if(val == "Aktionscode eingeben" || val == "") {
		Phire.sendNotification(Notifications.SHOW_ALERT_PANEL, {
			text : "Bitte geben Sie<br>Ihren Aktionscode ein!"
		});
		return;
	}
	Phire.sendNotification(Notifications.SHOW_PRELOADER, true);
	Phire.getModel("WebProxy").loginUsingToken(val);
}

MainModule.prototype.checkLoggedIn = function() {

	if(UserInfo.loggedIn) {
		$("#mainmodule_start").hide();
		$("#mainmodule_loggedin").show();
		$("#mainmodule_token").html(UserInfo.aktionscode);
	} else {
		$("#mainmodule_loggedin").hide();
		$("#mainmodule_start").show();
	}
};

