﻿var Sawbuck = window.Sawbuck || {}; Sawbuck.HashManager = (function() {
	var originalHash = window.location.hash.substr(1); var currentHash = originalHash; var isIE7orLess = (navigator.userAgent.match(/^.+MSIE\s[0-7]\..+$/)) ? true : false; var eventHandlers = new Array(); var timer = null; var checkHashDelegate, suppress; if (!isIE7orLess) { checkHashDelegate = Sawbuck.Utilities.createDelegate(this, checkHash); checkHash(); }
	function checkHash() {
		var hash = window.location.hash.substr(1); if (hash != currentHash) { raise({ "hash": hash, "app": false }); currentHash = hash; }
		timer = setTimeout(checkHashDelegate, 100);
	}
	function raise(args) { for (var i = 0; i < eventHandlers.length; i++) { eventHandlers[i](args); } }
	return { getOriginalHash: function() { return originalHash; }, getCurrentHash: function() { return currentHash; }, addHandler: function(eventHandler) { eventHandlers.push(eventHandler); }, newHash: function(hash) {
		if (currentHash != hash) {
			if (isIE7orLess) {
				suppress = true; location.hash = hash || "#"; try { var doc = document.getElementById("historyFrame").contentWindow.document; doc.open("javascript:'<html></html>'"); doc.write("<html><head><scri" + "pt type=\"text/javascript\">parent.Sawbuck.HashManager.onFrameLoaded('" + hash + "');</scri" + "pt></head><body></body></html>"); doc.close(); }
				catch (e) { } 
			} else { currentHash = hash; location.hash = hash || "#"; raise({ "hash": hash, "app": true }); } 
		} 
	}, onFrameLoaded: function(hash) {
		if (isIE7orLess) {
			if (hash == "original") { if (originalHash.length > 0) { location.hash = originalHash || "#"; raise({ "hash": originalHash, "app": suppress }); currentHash = originalHash; } else { location.hash = "#"; raise({ "hash": "", "app": suppress }); currentHash = ""; } } else { location.hash = hash || "#"; raise({ "hash": hash, "app": suppress }); currentHash = hash; }
			suppress = false;
		} 
	} }
	})();