$(document).ready(function() {
	Histry = {};
	Histry.pathname = null;
	Histry.previousHash = null;
	Histry.hashCheckInterval = -1;
	Histry.stack = [];
	Histry.initialize = function () {
		if (Histry.supportsHistoryPushState()) {
			Histry.pathname = document.location.pathname;
			$(window).bind("popstate", Histry.onHistoryChanged);
		} else {
			Histry.hashCheckInterval = setInterval(Histry.onCheckHash, 200);
		}
	};
	Histry.supportsHistoryPushState = function () {
		return ("pushState" in window.history) && window.history.pushState !== null;
	};
	Histry.onCheckHash = function () {
		if (document.location.hash !== Histry.previousHash) {
			Histry.navigateToPath(document.location.hash.slice(1));
			Histry.previousHash = document.location.hash;
		}
	};
	Histry.pushState = function (url) {
		if (Histry.supportsHistoryPushState()) {
			window.history.pushState("", "", url);
		} else {
			Histry.previousHash = url;
			document.location.hash = url;
		}
		Histry.stack.push(url);
	};
	Histry.onHistoryChanged = function (event) {
		if (Histry.supportsHistoryPushState()) {
			if(Histry.pathname != document.location.pathname){
				Histry.pathname = null;
				Histry.navigateToPath(document.location.pathname);
			}
		}
	};
	Histry.navigateToPath = function(pathname) {
		Histry.pushState(pathname);
	};
});

