
// the primary navigation mechanism is JS based
(function($) {
	var AppController = {
		activeNode: null,
		innerNode: null,
	    initialize: function() {
	        var self = this;
	        $('#content').each(function(index, node) {
	        	self.innerNode = node;
	        	return false;
	        });
	        $('#navigation li a.active').each(function(index, node) {
	            self.activeNode = node;
	            return false;
	        });
	    	$('#navigation li a').each(function(index, node) {
	    		node.onclick = function() {
	    			self._setActiveNode(this);
	    		}
	    	});
	    	if (document.location.hash && document.location.hash.length > 0) {
	    		this.setNavigationHash(document.location.hash);
	    		scroll(0,0);
	    	} else {
	    		this._setActiveNode(this.activeNode);
	    		scroll(0,0);
	    	}
	    },
	    setNavigationHash: function(hashString) {
	        hashString = hashString.substring(1);
	    	$('#navigation li a[id=' + hashString + ']').each(function(index, node) {
	    		node.onclick();
	    		return false;
	    	});
	    },
	    _setActiveNode: function(newNode) {
	        var activeNode = $(this.activeNode);
			activeNode.removeClass('active');
			$('#' + this.activeNode.id + '-content').each(function(index, node) {
			    node.style.display = 'none';
			});
		    $(newNode).addClass('active');
			this.activeNode = newNode;
			$('#' + newNode.id + '-content').each(function(index, node) {
			    node.style.display = 'block';
			});
			// scroll to the top
			window.location.hash = newNode.id;
			scroll(0,0);
            return false;
	    }
	}
	
	AppController.initialize();
})(jQuery);
