try {
		if (typeof Prototype == 'undefined') throw("common.js requires the prototypejs.org library");


/*	Page
		-----------------------------------------------	*/
		if (typeof Page != 'undefined') throw("Page is already defined.");
		var Page = {
		// Attributes
			name: "Page",
			version: "0.01",
			debugMode: true,
			rootElement: null,
			bodyElement: null,
			currentNavButton: null,
			currentSubNavButton: null,

		// Methods
			initialize: function() {
				if (this.debugMode && "console" in window) console.log(this.name + " (version " + this.version + ") has initialized.");

				// Indicate that JavaScript is available
				this.rootElement = $(document.getElementsByTagName("html")[0]);
				this.rootElement.addClassName("scriptable");
			},
			onDomLoaded: function(evt) {
				this.bodyElement = $(document.getElementsByTagName("body")[0]);
				
				var bodyClassNames = this.bodyElement.classNames().toArray();
				
				this.currentNavButton = this.getCurrentNavButton($("navigation"));
				
				// If there is no current nav button, attempt to set one based on the page URI (from the body tag)
				if (this.currentNavButton == null) {
					var pageURI = null;
					if (bodyClassNames.length > 0) {
						pageURI = String(bodyClassNames[0]);	// By convention, the page URI is the first class name (from the body element's class attribute)
					}
					if (pageURI == "home") pageURI = "";
					if (pageURI != null) {
						this.currentNavButton = this.setCurrentNavButton($("navigation"), pageURI);
					}
				}
				
				if ($("navigationSub") != null) {
					this.currentSubNavButton = this.getCurrentNavButton($("navigationSub"));
				
					// If there is no current sub nav button, attempt to set one based on the page URI (from the body tag)
					if (this.currentSubNavButton == null) {
						var pageURI = null;
						if (bodyClassNames.length > 1) {
							pageURI = String(bodyClassNames[1]);	// By convention, the sub page URI is the second class name (from the body element's class attribute)
						} else if (bodyClassNames.length > 0) {
							pageURI = String(bodyClassNames[0]);
						}
						if (pageURI != null) {
							this.currentSubNavButton = this.setCurrentNavButton($("navigationSub"), pageURI);
						}
					}
				}
			},
			getCurrentNavButton: function(targetNav) {
				var currentNavButton = null;
				$A(targetNav.getElementsByTagName("li")).each(function(nextNavButton) {
					if ($(nextNavButton).hasClassName("current")) {
						currentNavButton = $(nextNavButton);
					}
				}.bind(this));
				return currentNavButton;
			},
			setCurrentNavButton: function(targetNav, pageURI) {
				var currentNavButton = null;
				$A(targetNav.getElementsByTagName("a")).each(function(nextNavButton) {
					var uriArray = String($(nextNavButton).getAttribute("href")).split("/");
					var nextURI = "";
					if (uriArray.length > 0) {
						nextURI = uriArray[uriArray.length - 1];
					}
					//console.log("nextURI:" + nextURI + ":");
					//console.log("pageURI:" + pageURI + ":");
					if (nextURI == pageURI) {
						$(nextNavButton.parentNode).addClassName("current");
						currentNavButton = $(nextNavButton.parentNode);
					}
				}.bind(this));
				return currentNavButton;
			}
		};
		Page.initialize();
		Event.observe(window, "load", Page.onDomLoaded.bindAsEventListener(Page));


} catch(err) {
		if ("console" in window) console.log(err);
}


