function MainNavigation() {
	this.me = this
}

MainNavigation.prototype.notificationsList = [Notifications.LOGGED_IN, Notifications.NAV_STATE, Notifications.LOG_OUT];
MainNavigation.prototype.name = "MainNavigation";
MainNavigation.prototype.init = function(){
	Phire.placeTemplate("#mainnav_container", "MainNavigation.html", $.callback(this, this.onInit));
}



MainNavigation.prototype.onInit = function() {
	
	

	this.buttons = [];
	this.buttons["jobkompass"] = this.enableButton("#nav_jobkompass", true);
	this.buttons["jobtest"] = this.enableButton("#nav_jobtest", true);
	this.buttons["feelwell"] = this.enableButton("#nav_feelwell", true);
	this.buttons["fit"] = this.enableButton("#nav_fit", true);

	$("#nav_logo").click(function() {

		if(UserInfo.inTest) {
			Phire.sendNotification(Notifications.EXIT_TEST, "MainModule");
			return;
		}
		Phire.sendNotification(Notifications.SHOW_MODULE, {
			module : "MainModule"
		});

	});

	$("#nav_logout").hover(function() {

		$(this).addClass("logout_button_hover");
	}, function() {
		$(this).removeClass("logout_button_hover");
	});

	$("#nav_logout").click(function() {

		if(Main.currentModule.name != "MainModule") {
			Phire.sendNotification(Notifications.SHOW_ALERT_PANEL, {
				text : "Möchten Sie sich wirklich abmelden?",
				ok : "Ja",
				cancel : "Nein",
				callback : function(value) {
					if(value) {
						UserInfo.loggedIn = false;
						Phire.sendNotification(Notifications.LOG_OUT);
						Phire.sendNotification(Notifications.SHOW_MODULE, {
							module : "MainModule"
						});
					}
				}
			});
		} else {
			UserInfo.loggedIn = false;
			Phire.sendNotification(Notifications.LOG_OUT);
		}

		return;
	});

	this.clickedButton = "";
	$("#nav_logout").hide();

	var y = 88;
	switch(BrowserDetect.browser) {
		case "Opera":
		case "Chrome":
			y = 89;
			break;
		case "Explorer":
			if(BrowserDetect.version < 9)
				y = 91;
			break;
		case "Firefox":
			if(BrowserDetect.version < 5)
				y = 91;
			break;
		
	}
	$("#mainnav").css("top", y);

};

MainNavigation.prototype.handleNotification = function(notification, data) {

	switch (notification) {

		case Notifications.NAV_STATE:
			this.doClick(data);
			break;

		case Notifications.LOGGED_IN:
			$("#nav_logout").show();
			break;

		case Notifications.LOG_OUT:
			$("#nav_logout").hide();
			break;
	}
};

MainNavigation.prototype.doClick = function(id) {

	for(var i in this.buttons) {
		this.enableButton(this.buttons[i], true);
	};
	if(id != "")
		this.enableButton(this.buttons[id], false);
};

MainNavigation.prototype.enableButton = function(button, value) {
	var b = $(button);

	if(value) {
		b.unbind("click");
		b.click(function() {

			Phire.sendNotification(Notifications.NAVIGATE_TO, {
				nav : "#" + $(this).attr("id")
			});
		});
		b.hover(function() {
			$(this).addClass("nav_button_hover");

		}, function() {
			$(this).removeClass("nav_button_hover");
		});
		b.removeClass("nav_button_hover");
		b.addClass("cursor_pointer");

	} else {
		b.unbind("click mouseenter mouseleave");
		b.addClass("nav_button_hover");
		b.removeClass("cursor_pointer");
	}
	return button;
};

