(function(){function d(a){a=a.replace(f,"\\$&").replace(g,"([^/]+)").replace(h,"(.*?)");return RegExp("^"+a+"$")}var g=/:\w+/g,h=/\*\w+/g,f=/[-[\]{}()+?.,\\^$|#\s]/g,i=/^[#\/]/;o_O.router=o_O.model.extend({},{initialize:function(){this.routes=[]},add:function(a,b){404===a?this.routing_404={handler:b}:this.routes.push({regex:d(a),handler:b});return this},runRouting:function(a){for(var b=[],c=0;c<this.routes.length;c++){var e=this.routes[c];e.regex.test(a)&&b.push(e)}for(c=0;c<b.length;c++){var d=e.regex.exec(a).slice(1);
this.runRoute(b[c],d)}0==b.length&&this.routing_404&&this.runRoute(this.routing_404,[])},runRoute:function(a,b){"string"==typeof a.handler?(b.unshift(a.handler),this.emit.apply(this,b)):a.handler.apply(null,b)},getHash:function(){var a=window.location.href.match(/#(.*)$/);return a?a[1]:""},go:function(){this.location=this.getHash().replace(i,"");this.runRouting(this.location)},start:function(){var a=this;this.go();$(window).bind("hashchange",function(){a.go()})},redirect:function(a,b){if(!1===b)this.runRouting(a);
else{var c="#!"+a;document.location.hash==c?this.go():document.location.hash=c}}});o_O.extend(o_O.router.prototype,o_O.Events)}).call(this);
