/* stategraph v0.2.0 https://github.com/munro/stategraph | https://github.com/munro/stategraph/blob/master/LICENSE */ var StateGraph=function(a,b,c,d,e,f){function g(b,c,d){return a.bind.apply(a,[b,c].concat(d))}return"use strict",typeof f=="function"?f=f:f=function(a){function b(){}return b.prototype=a,new b},c=function(){this.states={},this.current=null,this.tree||(this.tree=[this])},c.VERSION="0.2.0",c.emitter=function(c){b=c,d.prototype=a.extend(f(c),e)},c.prototype={state:function(b,c){var e=this,f=a.toArray(arguments);return typeof b=="undefined"?e.current:typeof c=="undefined"?e.states[b]:f.length>2||typeof c=="string"?e.states[b].state.apply(e.states[b],f.slice(1)):e.states[b]=new d(c,e.tree)},go:function(b){var c=this,e;b instanceof d?e=b:e=c.states[b];if(!e)throw new Error("State `"+b+"` does not exist.");return c.current===e?e:(c.current&&c.current.end(),c.tree.length>=2&&a.chain(c.tree).last(2).reduce(function(a,b){a.go(b)}),c.current=e,e.enter.apply(e,a.toArray(arguments).slice(1)),e)},end:function(a){a=this,a.current&&a.current.end(),a._end&&a._end(),a.current=null}},d=function(c,d){var e=this;b.call(e),e.tree=d.concat([e]),d=a.rest(e.tree),e.enter=e._enter=function(){g(e.emit,e,["enter"].concat(d)).apply(e,arguments),g(c,e,d).apply(e,arguments)},e.end=e._end=g(e.emit,e,["leave"].concat(d))},d.prototype=a.extend(f(b.prototype),e={state:function(){return a.extend(this,c.prototype),c.call(this),c.prototype.state.apply(this,arguments)},jump:function(){var b=this,c=a.toArray(arguments);return a.reduce(b.tree,function(a,d,e){return a.go.apply(a,[d].concat(b.tree.length===e+1?c:[])),d})}}),c}(typeof _!="undefined"?_:require("underscore"),typeof EventEmitter!="undefined"?EventEmitter:require("events").EventEmitter);typeof module!="undefined"&&(module.exports=StateGraph);