/* # Hasher 2/6 (by Nijikokun <nijikokun@gmail.com>)
 * @license: MIT License <https://github.com/Nijikokun/Hasher>
 */
var Hasher={routes:[],regex:{HASH_STRIP:/^#!*/,ARG_NAMED:/:([\w\d]+)/g,ARG_SPLAT:/\*([\w\d]+)/g,ESC:/[-[\]{}()+?.,\\^$|#\s]/g},history:{cache:!1,support:"history"in window},marray:function(a){return Array.prototype.slice.call(a,0)},proxy:function(a){var b=this;return function(){return a.apply(b,arguments)}},proxyAll:function(){for(var a=this.marray(arguments),b=0;b<a.length;b++)this[a[b]]=this.proxy(this[a[b]])},add:function(a,b){if(typeof a=="object")for(var c in a)this.add(c,a[c]);else typeof a==
"string"&&(a=a.replace(this.regex.ESC,"\\$&").replace(this.regex.ARG_NAMED,"([^/]*)").replace(this.regex.ARG_SPLAT,"(.*?)"),a=RegExp("^"+a+"$")),this.routes.push({route:a,callback:b})},setup:function(a){if(a&&a.history)this.history.cache=this.history.support&&a.history;this.history.cache?$(window).bind("popstate",this.change):$(window).bind("hashchange",this.change);this.proxyAll("change");this.change()},unbind:function(){this.history?$(window).unbind("popstate",this.change):$(window).unbind("hashchange",
this.change)},navigate:function(){var a=this.marray(arguments),b=!1;typeof a[a.length-1]=="boolean"&&(b=a.pop());a=a.join("/");if(this.path!=a){if(!b)this.path=a;this.history.cache?history.cache.pushState({},document.title,this.getHost()+a):window.location.hash=a}},match:function(a,b,c){a=b.exec(a);if(!a)return!1;a=a.slice(1);c.apply(c,a);return!0},getPath:function(){return window.location.pathname},getHash:function(){return window.location.hash},getHost:function(){return(document.location+"").replace(this.getPath()+
this.getHash(),"")},getFragment:function(){return this.getHash().replace(this.regex.HASH_STRIP,"")},change:function(){var a=Hasher.history.cache?Hasher.getPath():Hasher.getFragment();if(a!=Hasher.path){Hasher.path=a;for(var b=0;b<Hasher.routes.length;b++){var c=Hasher.routes[b];if(Hasher.match(a,c.route,c.callback))break}}}};
