!function(){function t(t){for(var e=t.length,i=new Array(e),s=0;e>s;s++){var r=t[s],o=s==t.length-1?t[0]:t[s+1],n=pointAt(r,o);n.pointIdx=s;var h=r.speed&&r.speed/100||1;n.xRatio*=h;n.yRatio*=h;i[s]=n}return i}function e(t,e){if(0>e){t.x=t.dir.startX+t.relatedTo.x;t.y=t.dir.startY+t.relatedTo.y;t.xRatio=-t.dir.xRatio;t.yRatio=-t.dir.yRatio}else{t.x=t.dir.x+t.relatedTo.x;t.y=t.dir.y+t.relatedTo.y;t.xRatio=t.dir.xRatio;t.yRatio=t.dir.yRatio}return t}function i(t){QyEventTarget.call(this);this.at_end="stop";this.speed=100;t||(t={});this.setupOpt(t);var e;window.current_scene&&current_scene.classId&&(e=t[current_scene.classId]);if(!e)for(var i in t)if(t[i].points){e=t[i];break}e&&this.setupOpt(e)}inherits(i,QyEventTarget);window.QyPath=i;i.prototype.setSpeed=function(t){this.speed=t;if(this.target){var i=this.target.moveTarget_;if(i){e(i,t);t=Math.abs(t);this.target.setSpeed(t*i.xRatio,t*i.yRatio)}}return this};i.prototype.setPosition=function(t,e){e&&(t+=this.position);this.setupOpt({reversed:!1,position:t,speed:Math.abs(this.speed)});if(this.target&&this.target.moveTarget_){var i=this.getPoints()[this.position],s=this.getDirs()[this.position],r=this.target.moveTarget_,o=r.relatedTo;this.target&&this.target.setPosition(i.x+o.x,i.y+o.y,!0);this.moveOneStep(s,r);return this}};i.prototype.setupOpt=function(t){t||(t={});null!=t.closed&&(this.closed=t.closed);null!=t.at_end&&(this.at_end=t.at_end);null!=t.relative&&(this.relative=t.relative);null!=t.reversed&&(this.reversed=t.reversed);null!=t.speed&&(this.speed=t.speed);null!=t.points&&this.setPoints(t.points);if(null!=t.position&&this.points&&this.points.length>0){var e=this.points.length,i=t.position;this.position=0>i?e-1+i%e:i%e}else null==this.point&&(this.position=0)};i.prototype.setPoints=function(t){if(this.closed){this.points=new Array(t.length+1);for(var e=0;e<t.length;e++)this.points[e]=t[e];this.points[t.length]=t[0]}else this.points=t;delete this.revPoints;delete this.Dirs;delete this.revDirs};i.prototype.getPoints=function(){if(this.reversed){if(this.revPoints)return this.revPoints;for(var t=this.points.length,e=t-1,i=new Array(t),s=0;t>s;s++)i[s]=this.points[e-s];this.constructor.prototype.revPoints=i;return i}return this.points};i.prototype.getDirs=function(){if(!this.points||0==this.points.length)return[];if(this.reversed){if(this.revDirs)return this.revDirs;var e=t(this.getPoints());this.constructor.prototype.revDirs=e;return e}if(this.Dirs)return this.Dirs;var i=t(this.points);this.constructor.prototype.Dirs=i;return i};i.prototype.moveOneStep=function(t,e){e||(e={relatedTo:{x:0,y:0}});e.dir=t;this.target.moveTarget_=e;this.setSpeed(this.speed)};i.prototype.start=function(t){if(!this.target||this.started)return this;t&&this.setupOpt(t);var e=this.getDirs();if(0!=e.length)if(1!=e.length){var i=this.getPoints()[this.position],s=e[this.position],r={relatedTo:{x:0,y:0}},o=this.target.getPosition();this.targetStartPos={x:o.x,y:o.y};if(this.relative){var n=o.x-i.x,h=o.y-i.y;r.relatedTo.x=n;r.relatedTo.y=h}else{this.target.setPosition(i.x,i.y,!0);this.targetStartPos.x=i.x;this.targetStartPos.y=i.y;this.relative=!0}this.moveOneStep(s,r);this.started=!0;this.target.dispatchEvent("pathstart")}else this.relative||this.target.setPosition(e[0].x,e[0].y)};i.prototype.stop=function(){if(this.target&&this.started){delete this.target.moveTarget_;this.target.setSpeed(0);this.started=!1;return this}};i.prototype.reachPoint=function(t){var e=t.dir,i=this.points.length,s=0;this.speed<=0&&e.pointIdx<=0?s=1:this.speed>=0&&e.pointIdx>=i-2&&(s=2);if(s){this.position=0;this.target.dispatchEvent("pathend");switch(this.at_end){case"stop":this.stop();return;case"revert":if(1==s)this.setSpeed(-this.speed);else if(2==s){this.reversed=!this.reversed;this.stop();this.start()}return;case"recurse":this.target.setPosition(this.targetStartPos.x,this.targetStartPos.y,!0);case"continue":if(1==s)this.setSpeed(-this.speed);else if(2==s){this.stop();this.start()}return}}this.target.dispatchEvent({type:"pathpoint",pointIdx:e.pointIdx});var r=this.getDirs();e=r[(i+e.pointIdx+sign(this.speed))%i];this.moveOneStep(e,t)}}();