//-------------------------------
// Class
//-------------------------------

function NavigationApp() {
	
	var _self = this;

	//-------------------------------
	// Constants
	//-------------------------------
	
	_self.DISPLAY_TABS = "display_tab_items";
	_self.HIDE_TABS = "hide_tab_items";
	
	//-------------------------------
	// Properties
	//-------------------------------
	
	var _current;
	var _previous;
	
	//-------------------------------
	// Constructor
	//-------------------------------
	
	$(function() {
		init();
		
		$(".tab").bind(_self.DISPLAY_TABS, onDisplayTabs);
		$(".menuClose").bind(_self.HIDE_TABS, onHideTabs);
		$(".nav_featured").bind(_self.HIDE_TABS, onHideTabs);
	});
	
	//-------------------------------
	// Public Methods
	//-------------------------------
	
	//-------------------------------
	// Private Methods
	//-------------------------------
	
	function init() {
		
		$(".tab").click(function() {
			$(this).trigger(_self.DISPLAY_TABS, this);
		});
		
		$(".menuClose").click(function() {
			$(this).trigger(_self.HIDE_TABS);
		});
		
		$(".nav_featured").click(function() {
			$(this).trigger(_self.HIDE_TABS);
		});
		
		_previous = $(".nav_featured");
		
		$(_previous).addClass("shift");
	}
	
	function display(item) {
		$(_current).removeClass("shift");
		$(_previous).removeClass("shift");
		$("span", $("#tooltip")).stop().hide();

		$(".stretcher", $(_current)).slideUp();
		$(".stretcher", $(item)).slideDown(function() {
			if($(item).attr("id") == "nav_events") $("span", $("#tooltip")).fadeOut(2000, function() {
				$("#tooltip").show();
			}).fadeIn(1000).fadeTo(5000, 1).fadeOut(500, function() {
				$("#tooltip").hide();
			});
		});
		overlay("show");
	}
	
	function overlay(status) {
		if(status == "show") {
			$("#overlay").show();
			var pos = $("#overlay").position();
			$("#overlay").css("height", ($(document).height() - pos.top) + "px");
			
		}
		else if (status == "hide") {
			$("#overlay").hide();
		}
	}
	
	//-------------------------------
	// Listeners
	//-------------------------------
	
	function onDisplayTabs(event, item) {
		$(item).addClass("shift");
		
		if(item != _current) display(item);
		
		_current = item;
	}
	
	function onHideTabs(event) {
		
		$(".stretcher", $(_current)).slideUp(function() {
			$(_previous).addClass("shift");
			$(_current).removeClass("shift");
			_current = null;
		});
		overlay("hide");
	}
	
	//-------------------------------
	// Getters/Setters
	//-------------------------------
	
	//_self.varName = function() { return "variable"; }
	//_self.varName = function(setter) { "variable" = setter; }
}

