text: (function(e,t){if(!Function.prototype["bind"]){Function.prototype["bind"]=function(e){var t=this,n=Array.prototype.slice.call(arguments),e=n.shift();return function(){return t.apply(e,n.concat(Array.prototype.slice.call(arguments)))}}}var n="([^/]+)",r=/:([\w\d]+)/g,i=/\/\*(?!\*)/,s="/([^/]+)",o=/\*{2}/,u="(.*)",a=/\/*$/;var f=function(){this._routes=[];this._befores=[];this._errors={_:function(e,t,n){if(console&&console.warn)console.warn("Router.js : "+n)},_404:function(e,t){if(console&&console.warn)console.warn("404! Unmatched route for url "+t)},_500:function(e,t){if(console&&console.error)console.error("500! Internal error route for url "+t);else{throw new Error("500")}}};this._paused=false;e.onhashchange=function(t){if(!this._paused){this._route(this.extractFragment(e.location.href))}return true}.bind(this)};f.prototype.extractFragment=function(e){var t=e.indexOf("#");return t>0?e.substring(t):"#/"};f.prototype._throwsRouteError=function(e,t,n){if(this._errors["_"+e]instanceof Function)this._errors["_"+e](t,n,e);else{this._errors["_"](t,n,e)}return false};f.prototype._buildRequestObject=function(e,t,n){if(!e)throw new Error("Unable to compile request object");var r={};r.href=e;if(t)r.params=t;var i=e.split("?");if(i.length==2){var s=null;var o=i[1].split("&");r.queryString={};for(var u=0,a=o.length;u<a;u++){s=o[u].split("=");r.queryString[decodeURI(s[0])]=decodeURI(s[1])}}if(n&&n.length>0){r.splats=n}return r};f.prototype._followRoute=function(e,t,n){var r=n.splice(0,1),i=this._routes[r],s=t.match(i.path),o={},u={},a=[];if(!i){return this._throwsRouteError(500,new Error("Internal error"),e)}for(var f=0,l=i.paramNames.length;f<l;f++){u[i.paramNames[f]]=s[f+1]}f=f+1;if(s&&f<s.length){for(var c=f;c<s.length;c++){a.push(s[c])}}var h=n.length==0?null:function(t,n,r,i){return function(i,s){if(i)return this._throwsRouteError(s||500,i,e);this._followRoute(t,n,r)}.bind(this)}.bind(this)(e,t,n);o=this._buildRequestObject(e,u,a);i.routeAction(o,h)};f.prototype._routeBefores=function(e,t,n,r,i){var s;if(e.length>0){var o=e.splice(0,1);o=o[0];s=function(t,s){if(t)return this._throwsRouteError(s||500,t,n);this._routeBefores(e,o,n,r,i)}.bind(this)}else{s=function(e,t){if(e)return this._throwsRouteError(t||500,e,n);this._followRoute(n,r,i)}.bind(this)}t(this._buildRequestObject(n),s)};f.prototype._route=function(e){var t="",n=this._befores.slice(),r=[],i;var s=e;if(s.length==0)return true;s=s.replace(a,"");i=s.split("?")[0].replace(a,"");for(var o in this._routes){if(this._routes.hasOwnProperty(o)){t=this._routes[o];if(t.path.test(i)){r.push(o)}}}if(r.length>0){if(n.length>0){var u=n.splice(0,1);u=u[0];this._routeBefores(n,u,e,s,r)}else{this._followRoute(e,s,r)}}else{return this._throwsRouteError(404,null,e)}};f.prototype.pause=function(){this._paused=true};f.prototype.play=function(t){t="undefined"==typeof t?false:t;this._paused=false;if(t){this._route(this.extractFragment(e.location.href))}};f.prototype.setLocation=function(t){e.history.pushState(null,"",t)};f.prototype.redirect=function(e){this.setLocation(e);if(!this._paused)this._route(this.extractFragment(e))};f.prototype.addRoute=function(e,t){var f,l=[];if("string"==typeof e){e=e.replace(a,"");while((f=r.exec(e))!=null){l.push(f[1])}e=new RegExp(e.replace(r,n).replace(i,s).replace(o,u)+"$")}this._routes.push({path:e,paramNames:l,routeAction:t});return this};f.prototype.before=function(e){this._befores.push(e);return this};f.prototype.errors=function(e,t){if(isNaN(e)){throw new Error("Invalid code for routes error handling")}if(!(t instanceof Function)){throw new Error("Invalid callback for routes error handling")}e="_"+e;this._errors[e]=t;return this};f.prototype.run=function(t){if(!t){t=this.extractFragment(e.location.href)}t=t.indexOf("#")==0?t:"#"+t;this.redirect(t)};e.Router=f})(window)