var pageState = undefined; // READ ONLY
var inStateTransition=false; // RW SOMETIMES





// Modify this function to perform the state-changing action.
function stateChangeAction(state) { inStateTransition=true; // Don't forget to enable inStateTransition.

	clearPages();
	showPage(state);
	inStateTransition=false;

} // Remember to set inStateTransition false when done the transition.





function getAddressState() { return window.location.hash.substring(1); }
function setAddressState(newState) { window.location = "#"+newState; }

// This function is called to set a new state, for changing pages or similar.
function setState(newState) { if (!inStateTransition) { setAddressState(newState); stateChecker() } }

// Checks if the state has been changed, then performs the action.
function stateChecker() {
	if ( pageState!=getAddressState() && !inStateTransition ) {
		pageState=getAddressState();
		stateChangeAction(pageState);
	}
}

//// page.js usually calls this in jquery's window.load, or document.ready.
//setInterval(stateChecker, 100);
